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
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:
continued..
Kindly upvote . Thank you.
1. Modify larger.s to let the user to enter three numbers and output the largest value...
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...
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 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 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 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 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
In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted triangle. The height of the triangle will be given in $a0, and will be between 1 and 40 inclusive. For the first three tests, the included test harness should print (spimsimulator(dot)sourceforge(dot)net) 1. (25 pts.) In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted trian- gle. The height...
The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...
Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of 1's in the given number. For example: 1111 0000 should return 4 j main ############################################################### # Data Section .data # new_line: .asciiz "\n" space: .asciiz " " double_range_lbl: .asciiz "\nDouble range (Decimal Values) \nExpected output:\n1200 -690 104\nObtained output:\n" swap_bits_lbl: .asciiz "\nSwap bits (Hexadecimal Values)\nExpected output:\n75757575 FD5775DF 064B9A83\nObtained output:\n" count_bits_lbl: .asciiz "\nCount bits \nExpected output:\n20 24 13\nObtained output:\n" swap_bits_test_data: .word 0xBABABABA, 0xFEABBAEF, 0x09876543 swap_bits_expected_data: .word...