Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Here are the Cood and the assembly code tocomputenl. MIPS code: nt fact (int n) fact 1 (n 1) 1 else return n r adjust stack for 2 itens addi Ssp. Ssp, -8 fact (n save return address 3a0, 0(Ssp) save argument n Argument n in Sao test for Result in Szero, addi Sv0. Szero, 1 result is 1 addi ssp. ssp. pop 2 items from stack 9 LI: Addi Sao. Sa0 else decrement al fact 11 Salo, ogssp) restore original n 4 (ssp) stack multiply to get result addi Ssp, 5 15 jr Sra Suppose n 1, what instructions will be executed? write down all of them in the correct execution order. To save time, only listing the line numbers will be fine.)

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.