Runtime Stack Practice - Runtime Stack Practice Problems 1...

This preview shows page 1 - 2 out of 2 pages.

Runtime Stack Practice Problems 1. In the lecture, the functions leaf_example and max3 both saved registers on the stack. a. Why did leaf_example save $s0? b. Why did max3 save $ra? c. Why did max3 save $a0? d. Why did max3 not restore $a0? 2. A function is to call another function. Also changes the values in $s0, $s1, and $t0. a. Which registers should be saved? b. How much memory is needed to store the registers on the stack? 3. Complete the program by writing the function getinput as specified. getinput parameters $a0 address to store the first value $a1 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 .data num1: .word 0 num2: .word 0 prompt: .asciiz "Enter a number " endline: .asciiz "\n" .text .globl main main: ori $s0, $0, 5 # repeat 5 times top:

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture