Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(mips)I am looking for Fibonacci doing in recursive, below picture is ample code for factorial. I can get the right result for f0 and f1,
(mips)I am looking for Fibonacci doing in recursive, below picture is ample code for factorial. I can get the right result for f0 and f1, but the rest was weird. Thanks for your time and help.
main: Sa0, msg_str # load the address of the message "Enter some Number : " # prepare for syscall 4, printing string to the user # syscall 4 # prepare for syscall 5, reading integer from the user # syscall 5 # Now input integer is in $v0 . We cocy it to $a0 for syscall $vO, 5 $a0, $v0 fac syscall move function call # call "fac function and jump to fac tag # Now the result of fac (n) is in $v0. Copy it to $a0 for mov $a0, v0 sysc 1 # prepare for syscall 1, printing an integer # syscall 1 # prepare for syscall 10, finish syscall $v0,10 syscall fac "ret-one" if input is 0 branch # # make room for stack push . we must do this before recursive $a0, $zero, ret-one to addi $sp, $sp,-8 call Sa0,0 (Ssp) Sra ,4(Ssp) $a0 , $a0 ,-1 fac Sto,o (Ssp) Sra ,4 (Ssp) $sp, $sp,8 Sw SW addi # push input n to the stack # push return address to the stack # recursive call #pop input n back from the stack # pop return address from the stack # restore the stack addi # do n!-(n-1): * n, and prepare value n! for return # exit procedure mul ret ret one: $vO,1 # prepare value 1 for return retStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started