Odd/Even Number Identification and Sorting in MIPS Write a program in MIPS assem
ID: 670014 • Letter: O
Question
Odd/Even Number Identification and Sorting in MIPS
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
Explanation / Answer
Input and Output - System calls
Controlling the hardware responsible for input and output is a difficult and specialized job, and beyond the scope of this course. All computers have an operating system that provides many services for input/output anyway. The SPIM simulator provides 10 basic services. The ones we will be using right now are given here.
The others are for floating point (real) numbers. The call code always goes in $v0, and the system is called with syscall.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.