Question: Ben Bitdiddle is trying to compute the function f(a, b) = 2a + 3b for nonnegative b. He goes overboard in the use of function

Ben Bitdiddle is trying to compute the function f(a, b) = 2a + 3b for nonnegative b. He goes overboard in the use of function calls and recursion and produces the following high-level code for functions f and f2.?

// high-level code for functions f and f2 int f(int a, int

Ben then translates the two functions into assembly language as follows. He also writes a function, test, that calls the function f(5, 3).?

b) { int j: j = a; return j + a +

You will probably find it useful to make drawings of the stack similar to the one in Figure 6.26 to help you answer the following questions. (a) If the code runs starting at test, what value is in $v0 when the program gets to loop? Does his program correctly compute 2a + 3b??

(b) Suppose Ben deletes the instructions at addresses 0x0040001C and 0x00400044 that save and restore $ra. Will the program (1) enter an infinite loop but not crash; (2) crash (cause the stack to grow beyond the dynamic data segment or the PC to jump to a location outside the program); (3) produce an incorrect value in $v0 when the program returns to loop (if so, what value?), or (4) run correctly despite the deleted lines? (c) Repeat part (b) when the instructions at the following instruction addresses are deleted. Note that labels aren?t deleted, only instructions.?

(i) 0x00400018 and 0x00400030 (instructions that save and restore $a0)(ii) 0x00400014 and 0x00400034 (instructions that save and restore $a1)(iii) 0x00400020 and 0x00400040 (instructions that save and restore $s0)(iv) 0x00400050 and 0x00400088 (instructions that save and restore $sp)(v) 0x0040005C and 0x00400080 (instructions that save and restore $s0)(vi) 0x00400058 and 0x00400084 (instructions that save and restore $ra) (vii)0x00400054 and 0x00400078 (instructions that save and restore $a0)?

f2(b); } int f2(int x) { int k; k = 3; if

// high-level code for functions f and f2 int f(int a, int b) { int j: j = a; return j + a + f2(b); } int f2(int x) { int k; k = 3; if (x == 0) return 0; else return k + f2(x-1);

Step by Step Solution

3.50 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a v0 ends with 19 as desired b The program will 2 crash The jump register instruction jr ra at instr... 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!