Runtime Stack Practice Problems
In the lecture, the functions leaf_example and max3 both saved registers on the stack.
Why did leaf_example save $s0?
Why did max3 save $ra?
Why did max3 save $a0?
Why did max3 not restore $a0?
A function is to call another function.
Also changes the values in $s0, $s1, and $t0.
Which registers should be saved?
How much memory is needed to store the registers on the stack?
Complete the program by writing the function getinput as specified.
address to store the first value
address to store the second value
This function must call the getpos function two times and store each return
value into the memory locations given in $a0 and $a1. As this function calls another
function so you MUST save the $ra on the stack (not into another register)
# Program to read in two positive numbers and print their sum five times
num1: .word 0
num2: .word 0
prompt: .asciiz "Enter a number "
endline: .asciiz "\n"
ori $s0, $0, 5
# repeat 5 times