Question: 5 9 . 9 LAB: Function calls Given the following C program and the mapping of registers to variables, complete the MIPSzy implementation of Main.

59.9 LAB: Function calls
Given the following C program and the mapping of registers to variables, complete the MIPSzy implementation of Main. Do not implement return 0 ; in main().
```
int Dif(int a, int b){
return a - b;
}
int Sum(int a, int b){
return a + b;
}
int main(){
int x, y;
w = Sum(x, y);
z=Dif(y, x);
return 0; // Do not implement
}
```
Hints: Use program stack to pass arguments, return values, and preserve saved registers. Remember to pop the stack after each function returns.
Ex: If the values of \(\$ t 0\) and \(\$ 11\) are initialized in the simulator as:
\begin{tabular}{|c|c|}
\hline Registers & Data \\
\hline St0 & 5\\
\hline \$t1 & 10\\
\hline
\end{tabular}
the results are stored in St 2 and \(\$ \mathrm{t}3\) :
\begin{tabular}{|c|c|}
\hline Registers & Data \\
\hline \$t0 & 5\\
\hline\(\$ \mathbf{t 1}\) & 10\\
\hline \(\mathbf{\$ t 2}\) & \(\mathbf{15}\)\\
\hline \(\mathbf{\$ t 3}\) & \(\mathbf{5}\)\\
\hline
\end{tabular}
Note: Use the '+' button under the Registers display to initialize register values for \$t0 and St1.
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|l|}{Line 1 pddi \$sp,\$zero, 8188\# Assume progri}\\
\hline Line 2 & & \\
\hline Line 3 & \# Procedure Main & \\
\hline Line 4 & Main: & \\
\hline Line 5 & \# Type your code h & here. \\
\hline Line 6 & & \\
\hline Line 7 & & \\
\hline Line 8 & \( j \) End & \\
\hline Line 9 & & \\
\hline \multicolumn{3}{|l|}{Line 10\# Procedure Sum (Do not modify)}\\
\hline Line 11 & Sum: & \\
\hline Line 12 & Iw \$t0,8(\$sp) & \\
\hline Line 13 & lw \$t1,4(\$sp) & \\
\hline Line 14 & add \$t2.\$t0.\$t1 & \\
\hline
\end{tabular}
Line 14
add \(\$ \mathrm{t},\$ \mathrm{t}\theta,\$ \mathrm{tl}\)
Line 15
sw \$t2,0(\$sp)
Line 16
jr \$ra
Line 17
Line 18\# Procedure Dif (Do not modify)
Line 19 Dif:
Line 20 Iw \$t0,8(\$sp)
Line 21 lw \$t1,4(\$sp)
Line 22 sub \(\$ t 2,\$ t 0,\$ \) t1
Line 23
Line 24
sw \$t2,0(\$sp)
Line 25
jr \$ra
Line 26 End:
Line 27
5 9 . 9 LAB: Function calls Given the following C

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Programming Questions!