## fibonaci
## Registers used:
## $a0 - initially n.
## $t0 - parameter n.
## $t1 - fib (n - 1).
## $t2 - fib (n - 2).
.text
fib:
bgt $a0, 1, fib_recurse # if n < 2, then just return a 1,
li $v0, 1 # don't bother to build a stack frame.
jr $ra
# otherwise, set things up to handle
fib_recurse: # the recursive case:
subu $sp, $sp, 32 # frame size = 32, just because...
sw $ra, 28($sp) # preserve the Return Address.
sw $fp, 24($sp) # preserve the Frame Pointer.
addu $fp, $sp, 32 # move Frame Pointer to base of frame.
move $t0, $a0 # get n from caller.
# compute fib (n - 1):
sw $t0, 20($sp) # preserve n.
sub $a0, $t0, 1 # compute fib (n - 1)
jal fib
move $t1, $v0 # t1 = fib (n - 1)
lw $t0, 20($sp) # restore n.
# compute fib (n - 2):
sw $t1, 16($sp) # preserve $t1.
sub $a0, $t0, 2 # compute fib (n - 2)
jal fib
move $t2, $v0 # t2 = fib (n - 2)
lw $t1, 16($sp) # restore $t1.
add $v0, $t1, $t2 # $v0 = fib (n - 1) + fib (n - 2)
lw $ra, 28($sp) # restore Return Address.
lw $fp, 24($sp) # restore Frame Pointer.
addu $sp, $sp, 32 # restore Stack Pointer.
jr $ra # return.
main:
li $a0, 5 # fib (5) is what we are trying to find.
jal fib
move $a0, $v0
li $v0, 1
syscall
li $v0, 10
syscall
这是我的问题:当在main中调用jal fib时,函数操作是否知道在a0上运行,如果我在a1,a2中调用fib之前放了一些值...这会影响什么吗?
我也在添加输出消息时遇到问题:&#34;输入n来计算fib(n):&#34;然后当我收到&#34; n&#34;并把它放到$ a0,发现fib需要相当多的时间并且不断返回1或0 ..很奇怪。