Could someone help me out with this. I missed it on my test but teacher didn\'t
ID: 3835805 • Letter: C
Question
Could someone help me out with this. I missed it on my test but teacher didn't explain the answer well.
Explanation / Answer
answer 1,2,3,4,5,6,7,8.
explaination:
n=1 and given in your program n is stored in $a0 hence $a0=1;
instruction 1. as shown we adjust the stack for two items.
2. we store the return address in $ra on to stack.
what is return address in our case since n=1??
well see c code below
main{
return address---->display(fact(1))
}
i have called our funtion fact(1) in main an when it is done computing factorial of 1 it has to return back where it left.
so that i can display it. this return address is stored in $ra.
3. store the argument n on stack i.e 1
4. set less than i.e slti sets the $t0 to 1 if $a0<1 (so in our case $t0=1)
5. beq(branch if equal) to L1 if $t0=0 but in our case its is 1 hence we dont branch to L1 and instead go to next instruction
6 . add 0+1 and put in $v0 i. $v0=1;
7. delete the stack since it occupies memory
8. return to subroutine which called our program.