Question: Consider the following high-level function.? (a) Translate the high-level function f into MIPS assembly language. Pay particular attention to properly saving and restoring registers across

Consider the following high-level function.?

// C code int f(int n, int k) { int b; b

(a) Translate the high-level function f into MIPS assembly language. Pay particular attention to properly saving and restoring registers across function calls and using the MIPS preserved register conventions. Clearly comment your code. You can use the MIPS mul instruction. The function starts at instruction address 0x00400100. Keep local variable b in $s0.(b) Step through your function from part (a) by hand for the case of f(2, 4). Draw a picture of the stack similar to the one in Figure 6.26(c). Write the register name and data value stored at each location in the stack and keep track of the stack pointer value ($sp). Clearly mark each stack frame. You might also find it useful to keep track of the values in $a0, $a1, $v0, and $s0 throughout execution. Assume that when f is called, $s0 = 0xABCD and $ra = 0x400004. What is the final value of $v0??

= k + 2; if (n == 0) b = 10; else

// C code int f(int n, int k) { int b; b = k + 2; if (n == 0) b = 10; else b = b + (n * n) + f(n 1, k + 1); return b * k;

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a b The stack i after the last recursive call and ii after return The final value of v0 i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Digital Design Computer Questions!