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 02:00
Alocal reaction will occur at the site of the exposure such as irritation or damage to the skin eye or local reaction will occur at the site of the exposure such as irritation or damage to the skin ireland lounges
Answers: 3
question
Computers and Technology, 22.06.2019 17:00
Your computer running windows 10 is doing some very strange things with the operating system. you are fairly certain it is not a hardware issue. you need to try to get further insight into what is going on within the operating system. which tool would be best suited for this?
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
question
Computers and Technology, 24.06.2019 09:00
Why might you chose to crest a function resume
Answers: 1
You know the right answer?
Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe...
Questions
question
Mathematics, 19.09.2021 19:30
question
English, 19.09.2021 19:30
question
Biology, 19.09.2021 19:30
Questions on the website: 13722367