Question
1. Modify larger.s to let the user to enter three numbers and output the largest value # larger.s-- prints the larger of two numbers specified
1. Modify larger.s to let the user to enter three numbers and output the largest value
# larger.s-- prints the larger of two numbers specified # at runtime by the user. # Registers used: # $t0 - used to hold the first number. # $t1 - used to hold the second number. # $t2 - used to store the larger of $t1 and $t2. # $v0 - syscall parameter and return value. # $a0 - syscall parameter. .text
main: ## Get first number from user, put into $t0. li $v0, 5 # load syscall read_int into $v0. syscall # make the syscall. add $t0, $v0, $zero # move the number read into $t0.
## Get second number from user, put into $t1.
li $v0, 5 # load syscall read_int into $v0. syscall # make the syscall. add $t1, $v0, $zero # move the number read into $t1.
## put the larger of $t0 and $t1 into $t2.
slt $t2, $t0, $t1 # If $t0 < $t1, $t2 is 1, bne $t2, $zero,First # if $t2 is 1, go to First add $t2, $t0, $zero j Print # copy $t0 into $t2 First: add $t2, $t1, $zero
## Print out $t2.
Print: add $a0, $t2, $zero # move the number to print into $a0. li $v0, 1 # load syscall print_int into $v0. syscall # make the syscall.
## exit the program.
li $v0, 10 # syscall code 10 is for exit. syscall # make the syscall.
# end of larger.s
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started