Question

1. Modify larger.s to let the user to enter three numbers and output the largest value...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As mentioned , I have made few changes to larger.s . We can use move instead of add to make it easily understandable. Also I have compared the numbers using greater than or equal to, instead of lesser than.

# largest.s-- prints the larger of three numbers specified
# at run time by the user.
# Registers used:
# $t0 - used to hold the first number.
# $t1 - used to hold the second number.
# $t2 -used to hold the third number.
# $v0 - syscall parameter and return value.
# $a0 - syscall parameter.

.text
.align 2
.globl main

main:
# get the inputs from the user

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.

## Get third number from user, put into $t2.
li $v0, 5 # load syscall read_int into $v0.
syscall # make the syscall.
add $t0,$v0,$zero # third number in $t2

bge $t1, $t0, L1
move $t1, $t0 # largest number in $t1

bge $t2, $t1, L1
move $t2, $t1

L1:
li $v0, 4 # print answer
la $a0, answer
syscall

li $v0, 1 # print integer function call 1
move $a0, $t1 # integer to print
syscall

end: jr $ra

.data
answer: .asciiz "The largest number is "

The screenshots of code and output are:

C 1. Modily Laigers To Lel The Use xIO Assembly (MIPS, SPIM) Try IxG bye sl - Gooyle Serch Ctio.run/tispim По # load syscall readint into $v0. # make the syscall. - syscall add $tl, $v0, $zero # move the number, read into $t1 ## Get third number from user, put into $t2. Li $v0, 5 # load syscall read-int into $ve syscall add $t®,$v0, $zero # third number in $t2 # make the syscall. bge $tl, $t0, L1 move $t1, $t® # largest number in $t1 bge $t2, $tl, L1 move $t2, $tl L1: li $v0, 4 # print answe r la $a0, answer syscall Li $v0, 1 # print integer function call ! move $a@, $t1 # integer to print syscatl 11:55 PM 28/12019

continued..

е 1. Modify Layers Tu Lel The Us x IO Assembly (MIPS, SPIM)-Try 11 o G bye sll-Google Seurh Ctio.run/spim Πο 10 syscaLl end: jr $ra .data answer: .asciiz The largest number is Footer ▼ Input 5 Arguments ▼ Output The largest number is 5 Debug Loaded: /opt/spim/exceptions.s Real time: 0.011 s e袈礁 NG 28/1/2019

Kindly upvote . Thank you.

Add a comment
Know the answer?
Add Answer to:
1. Modify larger.s to let the user to enter three numbers and output the largest value...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS - Takes two inputs from the user, which are the lengths of two sides of...

    MIPS - Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle. See blue highlighted. preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    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,...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

  • what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​be...

    what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall

  • (USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point,...

    (USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point, write a program called LoadStore # Title : Memory access.asm #Desc: Practice initially memory, #in val1 = 0x0a; #int val2 = 0x0b; #int result; #string resultstring = " final answer : "; #string returnchar = "\n"; #void main() { #   result = val1 + val2; #   cout<<< resultstring << returnchar; #} .data val1: .word 0x0a   #store 0xa into variable val1 val2: .word 0x0b   #store...

  • Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...

    Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What is the address of label num3? _______________________________ Write the common syscall code to print string for the blank marked as #Question 2 _________________________________ Write proper comments for the lines marked as #Question 3 ________________________________________________________ Write the machine code for the line marked as #Question 4 in both binary and hex. Binary:_______________________________________ Hex:___________________ Write the machine code for the line marked as #Question 5 in...

  • 1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw        &

    1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw          $t0, 0($a0)         #load the first array value into $t0 addi      $t1, $0, 1            #intialize the counter to one loop:                   beq       $t1, $a1, exit     #exit if we reach the end of the array addi      $a0, $a0, 4         #increment the pointer by one word addi      $t1, $t1, 1          #increment the loop counter lw          $t2, 0($a0)         #store the next array value into $t2 slt          $t3, $t0, $t2       beq      ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT