Implementing subroutines using MIPS. In this lab we shall use the jal and jr commands
to implement subroutine calls.Write a program that reads in 4
numbers and prints out the maximum and minimum of the input numbers. A sample run of the
program will look like the following:
input a number: 13
input a number: 11
input a number: 19
input a number: 8
The maximum of the four numbers is 19
The minimum of the four numbers is 8
The requirements are as follows:
- Write a subroutine readtwo that prompts for and reads two integers and returns them to the
calling program. - Write a subroutine findminmax that takes 4 integers as input parameters and returns the
minimum and the maximum of these to the calling program. - Write a main program that calls readtwo twice to get the input and then calls findminmax
to complete the computation and prints the result. - Use all the appropriate MIPS conventions for the use of registers.
- Have your program checked for correctness during the lab and turn in a printout.
Sample Code that uses a subroutine call:
v0 – reads in an integer
t0 – holds the sum
a0 – points to strings to be printed
– also used to pass N to “sumup”
Sample Solution