Answer:
This question is not complete, here’s the full question:
Subroutines in MIPS Determine the minimum of two integers Functions within the MIPS slides explain how subroutines (also known as procedures, functions, and methods) can be utilized in MIPS. Given the significance of subroutines in contemporary programming, most hardware developers integrate mechanisms to support programmers. In high-level languages like C or Java, many aspects of subroutine calls are obscured from the saw. MIPS features special registers for passing information to and from a subroutine. The registers $a0, $a1, $a2, $a3 serve the purpose of conveying arguments into the relevant subroutine. The registers $v0 and $v1 transmit parameters back from the subroutine. The stack (and stack pointer register $sp) has various roles during the use of subroutines. It aids in transferring extra parameters to and from subroutines. Moreover, it holds temporary memory values that are necessary for a subroutine. Most crucially, it preserves the current state so that the subroutine can return to the caller once finished. This includes saving the frame pointer ($fp), the return address register ($ra), and the caller-saved registers ($s0-$s7). Suppose you need a program that accepts two integers from the user, determines the smaller of the two, and then prints the minimum value. One approach would involve creating a subroutine that takes two inputs and returns the lesser value. The following program illustrates one tactic to achieve this.
Explanation:
# minimum function to compute min($a0, $a1):
In the code below,
$a0 and $a1 are the input parameters
$v0 and $v1 represent the return value (holding the smaller one)
$ra indicates the return address
min:
blt $a0, $a1, firstIsLessThanLabel
blt $a1, $a0, secondIsLessThanLabel
firstIsLessThanLabel:
move $v0, $a0
secondIsLessThanLabel:
move $v0, $a1
jr $ra
Please note, for outputting, the following code should be used instead.
firstIsLessThanLabel: // this procedure is defined
li $v0, 4
la $a0, labelP1IsLess
syscall
b exitLabel
secondIsLessThanLabel: // this procedure is defined
li $v0, 4
la $a0, labelP2IsLess
syscall
b exitLabel
exitLabel: // this procedure is defined
li $vo, 10
syscall
The code below displays the entire program without the procedures:
.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