In this project, you write a MIPS code to 1) allow users to input a sequence of
ID: 645992 • Letter: I
Question
In this project, you write a MIPS code to
1) allow users to input a sequence of integers.
2) output the median of these integers.
The number of input integers is between 1 and 10. Your code should allow the users to input one by one, until a special integer 9999, which indicates the end of the input and should not be counted as the input integer.
Example:
Next input integer: -1
Next input integer: 2
Next input integer: 3
Next input integer: 9999
Median is: 2.
If there are even number of input integers, there are two input integers neighboring to the median in the sorted list. You should output the smaller one as the median in this project.
For example:
Next input integer: 1
Next input integer: 5
Next input integer: 2
Next input integer: 3
Next input integer: 9999
Median is: 2.
Explanation / Answer
.data num1: .asciiz " Enter the first number: " num2: .asciiz " Enter the second number: " num3: .asciiz " Enter the third number: " space: .asciiz ", " Median: .asciiz " The Median is : " .text main: # Print the prompt to enter the first number li $v0,4 la $a0, num1 syscall # Entering the first number li $v0,5 syscall move $t2,$v0 # Print the prompt to enter the second number li $v0,4 la $a0, num2 syscall # Entering the first number li $v0,5 syscall move $t3,$v0 #print the prompt for the third number li $v0, 4 la $a0, num3 syscall # Entering the third number li $v0, 5 syscall move $t5,$v0 # The if statement or conditional statement bgt $t2,$t3, bigger move $t4,$t3 bgt $t4,$t5, bigger1 move $t6,$t5 b endif bigger: move $t4,$t2 bigger1: move $t6,$t4 sub $t7,$t6,$t4 syscall endif: li $v0, 4 la $a0, Median syscall li $v0,1 move $a0,$t7 syscall #END OF PROGRAM li $v0,10 syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.