Question

In: Computer Science

Use MIPS write an assembly program which asks the user to enter 3 number. The program...

Use MIPS write an assembly program which asks the user to enter 3 number. The program
then sorts these numbers, the prints them from largest to smallest.

Solutions

Expert Solution

Code Screenshots:

Sample Output:

Code to Copy:

# Declare the required

# variables.

.data

    prompt1: .asciiz "Enter the first number: "

    prompt2: .asciiz "Enter the second number: "

    prompt3: .asciiz "Enter the third number: "

    msg: .asciiz "\nThe numbers in sorted order are as follows:\n"

    sp: .asciiz " "

.text

.globl main

main:

   # Prompt the user to

   # enter the first number.

   la $a0,prompt1                     

li $v0,4

   syscall

  

   # Read the number.

   li $v0,5                    

   syscall

  

   # Store the number in

   # the register t1.

   move $t1,$v0

  

   # Prompt the user to

   # enter the second number.

   la $a0,prompt2                 

   li $v0,4

   syscall

  

   # Read the number.

   li $v0,5

   syscall

  

   # Store the number

   # in the register t2.

   move $t2,$v0

  

   # Prompt the user to

   # enter the third number.

   li $v0, 4

   la $a0, prompt3

   syscall

  

   # Read the number.

   li $v0,5

   syscall

  

   # Store the number

   # in the register t3.

   move $t3, $v0

  

   # If the first number is

   # greater than the

   # second, jump to label L1.

   bge $t1, $t2, L1

  

   # Otherwise, swap the

   # first and second number.

   move $t0, $t1

   move $t1, $t2

   move $t2, $t0

  

   L1:

  

   # If the second number

   # is greater than the third,

   # jump to Label L2.

   bge $t2, $t3, L2

  

   # Otherwise, swap

   # the numbers.

   move $t0, $t2

   move $t2, $t3

   move $t3, $t0

  

   L2:

  

   # If the first number is

   # still greater than

   # the second, jump to the

   # label result.

   bge $t1, $t2, result

  

   # Otherwise, swap

   # the numbers.

   move $t0, $t1

   move $t1, $t2

   move $t2, $t0

  

   result:

  

   # Now, the numbers are stored

   # in descending order in the

   # registers $t1, $t2, and $t3

   # respectively.

  

   # Display an

   # informative message.

   li $v0, 4

   la $a0, msg

   syscall

  

   # Display the

   # number present

   # in register $t1.

   li $v0, 1

   la $a0, ($t1)

   syscall

  

   # Print a space.

   li $v0, 4

   la $a0, sp

   syscall

  

   # Display the

   # number present

   # in $t2.

   li $v0, 1

   la $a0, ($t2)

   syscall

  

   # Print a space.

   li $v0, 4

   la $a0, sp

   syscall

  

   # Display the number

   # present in $t3.

   li $v0, 1

   la $a0, ($t3)

   syscall

  

   # End the program.

   li $v0, 10

   syscall

  

   .end main


Related Solutions

Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a mips program that would function in QTSPIM that asks the user to enter a...
Write a mips program that would function in QTSPIM that asks the user to enter a list of integer values, one per line, with the last value being a negative. The program should read in these integers until a negative number is entered. Afterwards the program should print 1) sum, 2) minimum value, 3) max value, 4) mean and 5) variance value. of the numbers that were entered.
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
Write a program (polygon.py) that asks the user to enter the number of sides in a...
Write a program (polygon.py) that asks the user to enter the number of sides in a regular polygon. For example, an equilateral triangle is a regular 3-sided polygon, a square is a regular 4-sided polygon, and a pentagon is a regular 5-sided polygon. If a user enters a number of sides between 3 and 25, inclusive, draw the polygon and wait for the user to click on the screen to quit the program. If the user enters a number less...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT