源代码及操作说明
1.将zhongli.s和input.s放于英文目录下
2.依次加载zhongli和input
3.根据提示,先输入重力g,再输入阻力f
4.输入你想要输入的重力的个数
5.遗传输入重力和对应的高度。
注意:输入的数据应为整数
示例:
g:10
F:1
input An integer which is array's size value >1 :2
Weight:2
hight:1
Result:19
Weight:1
hight:2
Result:18
Zhongli.s
;*********** WINDLX Ex.1: Greatest common measure *************
;*********** (c) 2016 ccl *************
;*********** Modified 1992 Maziar Khosravipour *************
;------------------------------------------------------------------------
; Program begins at symbol main
; requires module INPUT
; Read two positive integer numbers from stdin, calculate the gcm
; and write the result to stdout
;------------------------------------------------------------------------
.data
;*** Prompts for input
Prompt: .asciiz \"input An integer which is array's size value >1 : \"
Prompt1: .asciiz \"Weight:\"
Prompt2: .asciiz \"hight: \"
Prompt3: .asciiz \"g: \"
Prompt4: .asciiz \"f: \"
;*** Data for printf-Trap
PrintfFormat: .asciiz \"result : %f \\n\"
.align 2
PrintfPar: .word PrintfFormat
Printf: .space 8
Printf1: .space 128
Printf2: .space 128
Printf3: .space 128
Printf4: .space 128
PrintfValue1: .space 128
PrintfValue2: .space 128
PrintfValue3: .space 128
.text
.global main
main:
;*** Read value from stdin into R1
addi r1,r0,Prompt3
jal InputUnsigned ;read uns.-integer into R1
add r7,r1,r0 ;R2 <- R1
sw Printf1,r7
lf f7, Printf1; g
cvti2d f8,f7
addi r1,r0,Prompt4
jal InputUnsigned ;read uns.-integer into R1
add r10,r1,r0 ;R2 <- R1
sw Printf2,r10
lf f10, Printf2; f
cvti2d f12,f10
addi r1,r0,Prompt
jal InputUnsigned
add r2,r0,r1
add r3,r0,r2
add r9,r0,r3
add r6,r0,r3
loop:
addi addi beqz
addi jal sw lf cvti2d r4,r0,0
r5,r0,0
r2, finish
r1,r0,Prompt1
InputUnsigned
PrintfValue1(r0),r1 f3, PrintfValue1(r0); f0,f3
weight
addi r1,r0,Prompt2
jal InputUnsigned
sw lf cvti2d multd multd multd subd sd addi trap PrintfValue1(r0),r1 f3, PrintfValue1(r0); f2,f3
f6,f2,f0
f6,f8,f6
f14,f2,f12
f18,f6,f14
Printf,f18
hight
r14,r0,PrintfPar
5
subi r2,r2,1
j loop
;*** end
finish: trap 0
Input.s
;*********** WINDLX Ex.1: Read a positive integer number *************
;*********** (c) 1991 G黱ther Raidl *************
;*********** Modified 1992 Maziar Khosravipour *************
;-----------------------------------------------------------------------------
;Subprogram call by symbol \"InputUnsigned\"
;expect the address of a zero-terminated prompt string in R1
;returns the read value in R1
;changes the contents of registers R1,R13,R14
;-----------------------------------------------------------------------------
.data
;*** Data for Read-Trap
ReadBuffer: .space 80
ReadPar: .word 0,ReadBuffer,80
;*** Data for Printf-Trap
PrintfPar: .space 4
SaveR2: .space 4
SaveR3: .space 4
SaveR4: .space 4
SaveR5: .space 4
.text
.global InputUnsigned
InputUnsigned:
;*** save register contents
sw SaveR2,r2
sw SaveR3,r3
sw SaveR4,r4
sw SaveR5,r5
;*** Prompt
sw PrintfPar,r1
addi r14,r0,PrintfPar
trap 5
;*** call Trap-3 to read line
addi r14,r0,ReadPar
trap 3
;*** determine value
addi addi addi Loop: lbu seqi bnez subi multu add addi j r2,r0,ReadBuffer
r1,r0,0
r4,r0,10 ;Decimal system
;*** reads digits to end of line
r3,0(r2)
r5,r3,10 ;LF -> Exit
r5,Finish
r3,r3,48 ;??
r1,r1,r4 ;Shift decimal
r1,r1,r3
r2,r2,1 ;increment pointer
Loop
Finish: lw lw lw lw jr
;*** restore old register contents
r2,SaveR2
r3,SaveR3
r4,SaveR4
r5,SaveR5
r31 ; Return
因篇幅问题不能全部显示,请点此查看更多更全内容