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 03:00
How can i clip a picture to a question on the computer?
Answers: 1
question
Computers and Technology, 22.06.2019 10:00
When is an original work considered public domain? a. when posted via social media b. when it is posted on the internet c. when a copyright symbol is not included with the piece of work d. when explicit permission is given by the author / owner
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Quic which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 11:30
Auser is given read permission to a file stored on an ntfs-formatted volume. the file is then copied to a folder on the same ntfs-formatted volume where the user has been given full control permission for that folder. when the user logs on to the computer holding the file and accesses its new location via a drive letter, what is the user's effective permission to the file? a. read b. full control c. no access d. modify e. none of the above
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, 15.12.2019 11:31
Questions on the website: 13722367