subject

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.

I need the code for the section prompted below:

## min_btw_2num. asm-- takes two numbers A and B
## Compare A and B
## Print out the smaller one
## Registers used:
## You can define by yourself!
.data
p1: .asciiz "Please enter the 1st integer: "
p2: .asciiz "Please enter the 2nd integer: "
.text
main:
# Get numbers from user
li $v0, 4 # Load 4=print_string into $v0
la $a0, p1 # Load address of first prompt into $a0
syscall # Output the prompt via syscall
li $v0, 5 # Load 5=read_int into $v0
syscall # Read an integer via syscall
add $s0, $v0, $zero # Copy from $v0 to $s0
li $v0, 4 # Load 4=print_string into $v0
la $a0, p2 # Load address of second prompt into $a0
syscall # Output the prompt via syscall
li $v0, 5 # Load 5=read_int into $v0
22
syscall # Read an integer via syscall
add $s1, $v0, $zero # Copy from $v0 to $s1
# Compute minimum
add $a0,$s0,$0 # Put argument ($s0) in $a0
add $a1,$s1,$0 # Put argument ($s1) in $a1
jal minimum # Call minimum function, result in $v0
# Output results
add $a0, $v0, $zero # Load sum of inupt numbers into $a0
li $v0, 1 # Load 1=print_int into $v0
syscall # Output the prompt via syscall
# Exit
li $v0, 10 # exit
syscall
# minimum function to compute min($a0, $a1):
||
|Put your code here|
||
return:

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
What does 21 pilots middle aged name as a band 15 years prior to them naming their band 21 pilots?
Answers: 1
question
Computers and Technology, 24.06.2019 09:40
Healthy study habits are best described as
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
What was the advantage of using transistors instead of vacuum tubes in the second-generation computers? a. computers were drastically reduced in size. b. computers no longer produced errors. c. computers became affordable. d. computers could run on electricity.
Answers: 1
question
Computers and Technology, 25.06.2019 04:40
1. instructions: in your response, make an argument for whether for whether it is better for waketown to build its new wake heights subdivision or to preserve the wake wetlan to preserve the wake wetland preserve. use evidence from at least two of the sources below to support your claim. be sure to introduce your precise claim, develop the claim with evidence from the sources, and demonstrate relationships between ideas. (15 points)
Answers: 2
You know the right answer?
Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe...
Questions
question
Health, 02.10.2019 23:20
question
Biology, 02.10.2019 23:20
Questions on the website: 13722361