Question: Consider following procedure calls implemented in MIPS. Assume the implementation of each function in each case is unknown. Case 1: main calls function sum() and
Consider following procedure calls implemented in MIPS. Assume the implementation of each function in each case is unknown.
Case 1: main calls function sum() and sum() calls function bin(). Both sum() and bin() are void functions which take no parameters. In the body of sum(), $s1, $s2 registers are used before and after bin() function call. Function bin() also uses $s1 and $s2
Case 2: main calls function sum(int n) which returns an integer and takes an integer parameter. Function sum(int n) is described below:
int sum(int n) {
if (n == 0) { return 0;}
return n+ sum(n - 1) + sum( n - 2);
}
Case 3: main calls funcA() and funcA() calls funcB(). Both funcA() and funcB() are void functions which take no parameters. funcA() uses $a0, $s2, $t0, $t1 before and after funcB() function call. Function funcB() uses $v0, $s1, $t0, $a0, $s5.
Answer the following questions; adhere to register saving conventions when answering each problem. Each answer should contain specific register names (i.e $s1), not generalized statements like saved/temporary registers.
1. For Case 1, which registers should be pushed to the stack in the body of main?
2. For Case 2, which registers should be pushed to the stack in the body of function sum(int n)?
3. For Case 3, which registers should be pushed to stack in the body of function funcB()?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
