Write a program in MIPS assembly language that takes a set of signed 32-bit inte
ID: 670295 • Letter: W
Question
Write a program in MIPS assembly language that takes a set of signed 32-bit integers (words) as the input, classifies them into odd and even numbers, and then sorts the odd numbers and even numbers, respectively.
The input set integers are read from the console and the output sorted numbers are also in displayed in the console. For the input, a “special value” 9999 will be used to signify the end of the input sequence and this value is not to be considered part of the input data set. However, any value greater than 9999 that is entered prior to 9999 is considered as a valid input. Zero and negative values are also valid. All odd-number sets and all even-number sets are also valid.
The output sorting result should be in ascending order. For example,
With an input:
23, 34, 2, 57, -1, 64, 71 (9999)
the outputs should be
(Sorted even numbers) 2, 34, 64
(Sorted odd numbers) -1, 23, 57, 71
The input can be read in from the console one by one (with “ENTER” key after each input number) until “9999” is entered. The input set cannot be empty. You can use the following line to set up memory to hold the input:
.data
vals: .space 4000
THE PROGRAM MUST TAKE USER INPUT! BUT AT THE VERY LEAST USE THE NUMBERS PROVIDED IN THE DISCRIPTION AND SEPERATE THE EVEN FROM THE ODD. THANK YOU!
Explanation / Answer
CODE :
main:
# Get input value
addi $v0, $zero, 4 # Write Prompt
la $a0, prompt
syscall
addi $v0, $zero, 5 # Retrieve input
syscall
move $s0, $v0
# Check if odd or even
addi $t0, $zero, 2 # Store 2 in $t0
div $t0, $s0, $t0 # Divide input by 2
mfhi $s1 # Save remainder in $s1
# Print output
addi $v0, $zero, 4 # Print result string
la $a0, result
syscall
addi $v0, $zero, 1 # Print result
move $a0, $s1
syscall
#Exit program
addi $v0, $zero, 10
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.