MIPS Non-leaf Function Assignment

For this assignment you will write a MIPS program that contains a leaf function and a non-leaf function. In the non-leaf function you will need to store items on the stack.

C Program

The program you write will have the same functionality as the program contained in non_leaf_function.c, which came with the assignment. Write your MIPS program in non_leaf_function.s.

The functions function_one() and function_two() are exactly the same as in the C code we went through in class. See the class notes for my annotated version.

I added one extra line to main(). After printing out the value of z, the program prints out z + x. This means that main() needs to retain the value of x after function_one() returns.

Using $s0

In the main portion of your MIPS program, put the value of x in the register $s0 before calling function_one. function_one is also going to use the register $s0 to store its z variable, so before function_one uses $s0 it must store on the stack the value that main stored in $s0.

Using the Stack

In the factorial.s program (which you can find under class code), $ra and $a0 are stored on the stack in the factorial function. In function_one we need to store $ra and $s0 on the stack instead. After function_one does its work, it will restore the old values of $ra and $s0 from the stack.

Example Output

Here is what a run of your program should look like:

Enter x: 10
Enter y: 20
z: 6200
z + x: 6210

Submission

Push your program back to git-keeper. For full credit your program must adhere to the following requirements: