Question: Implementing subroutines using MIPS. In this lab we shall use the jal and jr commands to implement subroutine calls. The assignment requires you to write

 Implementing subroutines using MIPS. In this lab we shall use thejal and jr commands to implement subroutine calls. The assignment requires youto write a program that reads in 4 numbers and prints outthe maximum and minimum of the input numbers. A sample run of

Implementing subroutines using MIPS. In this lab we shall use the jal and jr commands to implement subroutine calls. The assignment requires you to 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: Please input a number: 13 Please input a number: 11 Please input a number: 19 Please 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: 1. Write a subroutine readtwo that prompts for and reads two integers and returns them to the calling program. 2. Write a subroutine findminmax that takes 4 integers as input parameters and returns the minimum and the maximum of these to the calling program. 3. Write a main program that calls readtwo twice to get the input and then calls findminmax to complete the computation and prints the result. 4. Use all the appropriate MIPS conventions for the use of registers. 5. Have your program checked for correctness during the lab and turn in a printout. Sample Code that uses a subroutine call: ## vo - reads in an integer ## to - holds the sum ## ao - points to strings to be printed ## also used to pass N to "sumup" text segment # # .text .globl - start main: # execution starts here la $a0, prompt 1 # print prompt on terminal li $v0,4 # system call to print syscall # out a string li $v0,5 # syscall 5 reads an integer syscall 1 move $a0, $v0 # copy the integer to $a0 jal sumup # procedure/function call move $t0, $v0 # copy the sum to $t0 la $a0, ans1 # print string before the sum li $v0,4 syscall move $a0,$t0 # print the sum li $v0,1 syscall la $a0, endl # syscal to print out li $v0,4 # a new line syscall li $v0,10 # exit syscall # Bye! ## The function "sumup" will calculate the sum of ## the integers from 1 to N (N will be passed to ## the function "sumup" in register $a0, and ## the sum will be returned in $v0). sumup: move $v0, $0 # Initialize the sum to O #li $v0, 0 # OR initialize it this way loop: add $v0, $v0, $a0 # $v0 = $v0 + $a0 addi $a0, $a0, -1 # $a0 = $a0 - 1 bnez $a0, loop # branch to loop if $a0 != 0 jr $ra # return to the calling function # data segment # .data prompt1: .asciiz "Please enter an integer: ans1: asciiz "The sum is" endl: .asciiz " " ## ## end of file sum.s

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!