问题描述
这是简单的阶乘程序。
.global main
main:
mov r0,#7 // insert here the number to calculate the factorial,e.g. 7
mov r1,r0 // it will be useful after
push {ip,lr} // save the lr
bl factorial // jump to factorial label
pop {ip,lr} // reset the lr so the program can return
bx lr
factorial:
cmp r1,#1 // if r1=1
moveq pc,lr // then return
sub r1,r1,#1 // else r1 = r1-1
mul r0,r0 // and multiply r0*r1
b factorial // then do it again until moveq return to main
如果我执行它,则会收到错误结果(非常低):
$ ./a.out
$ echo $?
176
176而不是5040 .. 一定有逻辑错误,您能帮我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)