Ben Bitdiddle is trying to compute the function f(a, b) = 2a + 3b for nonnegative b.
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 calls and recursion and produces the following high-level code for functions f and f2.?
Ben then translates the two functions into assembly language as follows. He also writes a function, test, that calls the function f(5, 3).?
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)?
Step by Step Answer:
Digital Design and Computer Architecture
ISBN: 978-0123944245
2nd edition
Authors: David Harris, Sarah Harris