回复 楼主 心中的十九
;*********** WINDLX Ex.3: Factorial
*************
;*********** (c) 1991 G黱ther Raidl
*************
;*********** Modified: 1992 Maziar Khosravipour *************
;--------------------------------------------------------------------------
; Program begin at symbol main
; requires module INPUT
; read a number from stdin and calculate the factorial (type: double)
; the result is written to stdout
;--------------------------------------------------------------------------
.data
Prompt:
.asciiz
"An integer value >1 : "
PrintfFormat:
.asciiz
"Factorial = %gnn"
.align
2
PrintfPar:
.word
PrintfFormat
PrintfValue:
.space
8
.text
.global
main
main:
;*** Read value from stdin into R1
addi
r1,r0,Prompt
jal
InputUnsigned
;*** init values
;movi2fp
f10,r1
;R1 -> D0
D0..Count register
addi
r5,r0,0
addi
r7,r0,1
;1 -> D2
D2..result
addi
r9,r7,0
addi
r2,r0,0
addi
r8,r0,2
divu
r3,r1,r8
addi
r4,r0,2
addf
f16,f17,f18;
addf
f15,f19,f20;
loop:
seq
r6,r5,r3
bnez
r6,Finish
add
r2,r2,r4
add
r4,r4,r8
add
r5,r5,r9
seq
r6,r5,r3
bnez
r6,Finish
add
r2,r2,r4
add
r4,r4,r8
add
r5,r5,r9
seq
r6,r5,r3
bnez
r6,Finish
add
r2,r2,r4
add
r4,r4,r8
add
r5,r5,r9
j
loop
Finish:
;*** write result to stdout
movi2fp
f11,r2
cvti2d
f2,f11
sd
PrintfValue,f2
addi
r14,r0,PrintfPar
trap
5
;*** end
trap
0