体系结构试验--DLX指令集--myFACT.…

;--------------------------------------------------------------------------
; 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 = %g\n\n" ;输出格式,表示求出的阶乘按什么格式输出
.align 2  ; 表示下面采用字对齐
PrintfPar: .word PrintfFormat
PrintfValue: .space 8

.text ; 第一代码段,默认情况下代码段$CODE会加载到内存0x100地址处 .global main ; 即该代码段的首地址
main:
addi r1,r0,Prompt ;Read value from stdin into R1
jal InputUnsigned ; 跳转到InputUnsigned子程序处读取输入的参数,同时将一条指令的地址存与r31中,即r31<-pc+4
                addd f2,f2,f0
                addd f4,f4,f6
;*** init values
movi2fp f10,r1 ;R1 -> D0 D0..Count register
cvti2d f0,f10
addi r2,r0,1 ;1 -> D2 D2..result
movi2fp f11,r2
cvti2d f2,f11
movd f4,f2 ;1-> D4 D4..Constant 1
;*** Break loop if D0 = 1
Loop: led f0,f4 ;D0<=1 ?
bfpt Finish
;*** Multiplication and next loop
multd f2,f2,f0
subd f0,f0,f4
                subd             f0,f0,f4
j Loop

Finish: ;*** write result to stdout
sd PrintfValue,f2
addi r14,r0,PrintfPar
trap 5
;*** end
trap 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值