CONVERT C++ CODE TO MIPS CODE
In class, we compiled a program with functions. A slightly different program is below (modifications in bold):
main() {
x = 2 * foo(4 * y + 4);
x = x + (4 * y + 4);
}
int foo(int n) {
int magic[8]; // Mod 1 - assume magic is stored above (i.e., lower address) junk on stack
int junk[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
junk[4] += 2 - magic[5]; // Mod 2
if (n < 1) return 1;
else return 2 * bar(n, 1, 2, 3, 4, 5) + junk[4] + foo(n - 1); // Mod 3
}
Modify the assembly language we wrote in class for this revised program (bar is of course a function that has already been written properly). Obviously, you need to use the procedure convention described in class and posted on bb. In cases where the convention was left unspecified, use the convention of the example. Also note that we need to call bar before foo as in the HLL code, since the compiler doesn't know whether bar has side effects such as [unadvisedly] playing with pointers to modify a variable in foo. Make sure to use a different ink color (or boldface font) to make your modifications clear, and label your program to indicate which changes support which mod. DO NOT change the original code, except as needed for these modifications.