Answer:
This question is incomplete, here's the complete question:
Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0, $a1, $a2, $a3 are used to pass arguments (or parameters) into the subroutine. The registers $v0 and $v1 are used to pass arguments (or parameters) back from the subroutine. The stack (and stack pointer register $sp) is used for a variety of things when using subroutines. The stack is used to pass additional parameters to and from subroutines. It is also used to hold temporary values in memory that a subroutine may need. Most importantly, it is used to save the current state so the subroutine can return back to the caller once it has completed. This includes the frame pointer ($fp), the return address register ($ra), and the caller-saved registers ($s0-$s7). Imagine you would like a program that reads two integers from the user, determine the smaller of the two, then prints the minimum value. One way to do this would be to have a subroutine that takes two arguments and returns the smaller of the two. The program shown below illustrates one way to do this.
Step-by-step explanation:
# minimum function to compute min($a0, $a1):
In this code below,
$a0, $a1 are arguments
$v0, $v1 are return value (which storing the value which is less than other)
$ra is return address
min:
blt $a0, $a1, firstIsLessThanLabel
blt $a1, $a0, secondIsLessThanLabel
firstIsLessThanLabel:
move $v0, $a0
secondIsLessThanLabel:
move $v0, $a1
jr $ra
Kindle note that, if you want to print: you are to use this code instead.
firstIsLessThanLabel: // procedure is created
li $v0, 4
la $a0, labelP1IsLess
syscall
b exitLabel
secondIsLessThanLabel: // procedure is created
li $v0, 4
la $a0, labelP2IsLess
syscall
b exitLabel
exitLabel: // procedure is created
li $vo, 10
syscall
The below codes is the entire code without procedure:
.data
p1: .asciiz "Please enter the 1st integer: "
p2: .asciiz "Please enter the 2nd integer: "
labelP1IsLess: .asciiz "first number is less than second number"
labelP2IsLess: .asciiz "second number is less than first number"
.text
main:
li $v0, 4
la $a0, p1
syscall
li $v0, 5
syscall //read the input
move $8, $v0
li $v0, 4
la $a0, p2
syscall
li $v0, 5
syscall
move $9, $v0
blt $8, $9, firstIsLessThanLabel
blt $9, $8, secondIsLessThanLabel
b exitLabel
firstIsLessThanLabel:
li $v0, 4
la $a0, labelP1IsLess
syscall
b exitLabel
secondIsLessThanLabel:
li $v0, 4
la $a0, labelP2IsLess
syscall
b exitLabel
exitLabel:
li $vo, 10
syscall