Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MUST BE IN MIPS LANGUAGE!!!! write a MIPS code to: 1) allow users to input a seq

ID: 3762431 • Letter: M

Question

MUST BE IN MIPS LANGUAGE!!!!

write a MIPS code to:

1) allow users to input a sequence of float point numbers (single precision number).

2) output the max, min, and median of these numbers. Your code should allow the users to input the float point number one by one, until a special number 0.0, which indicates the end of the input and should not be counted as the input number.

Example:

Next input integer: -1.0

Next input integer: 2.1

Next input integer: 3.2

Next input integer: 0.0

Max is: 3.2

Min is: -1.0

Median is: 2.1

If there are even number of inputs, there are two input numbers neighboring in the median position. You should output the average of them as the median in this project.

For example:

Next input integer: -1.5

Next input integer: 5.3

Next input integer: 2.4

Next input integer: 4.4

Next input integer: 0.0

Max is: 5.3

Min is: -1.5

Median is: 3.4

Your code must be compiled and tested in the MARS (http://courses.missouristate.edu/kenvollmar/mars/).

Explanation / Answer

move  $t0, $a0
move  $t1, $a1
li  $t3, 0
lw  $t2, ($t0)
sw  $t2, ($a2)   # min returned

sub  $t2, $t1, 1
sll  $t2, $t2, 2
add  $t3, $t2, $t0
lw  $t5, ($t3)
lw  $t4, ($sp)
sw  $t5, ($t4)   # max returned

srl  $t2, $t1, 1
sll  $t2, $t2, 2
add  $t2, $t2, $t0
lw  $t3, ($t2)
sw  $t3, ($a3)
rem  $t4, $t1, 2
bnez  $t4, med_done
subu  $t2, $t2, 4
lw  $t5, ($t2)
add  $t3, $t3, $t5
srl  $t3, $t3, 1
sw  $t3, ($a3)
med_done:

li  $t2, 0
move  $t4, $t1
sum_loop:
lw  $t3, ($t0)
add  $t2, $t2, $t3
add  $t0, $t0, 4
sub  $t4, $t4, 1
bnez  $t4, sum_loop

lw  $t3, 4($sp)
sw  $t2, ($t3)   # sum returned

mtc1  $t2, $f6   # $t2 = sum
cvt.s.w $f6, $f6   # convert int to float

mtc1  $t1, $f8   # $t2 = len
cvt.s.w $f8, $f8   # convert int to float

div.s  $f10, $f6, $f8   # ave in f10

lw  $t3, 8($sp)
s.s  $f10, ($t3)

jr  $ra
.end areaStats

YOU CAN TRY THIS ALSO

.globl stats
.ent stats
stats:
subu $sp, $sp, 12
sw $s0, 0($sp)
sw $fp, 4($sp)
sw $ra, 8($sp)
addu $fp, $sp, 12
# -----
# Find min.
lw $t0, ($a0)
sw $t0, ($a2)   #minimum, first element of array
# -----
#Find max.
subu $t0, $a1, 1
mul $t0, $t0, 4
addu $t0, $t0, $a0
lw $t1, ($t0)
sw $t1, ($fp)   #maximum, last element of array
# -----
# Find median.
lw $t0, ($a0)
move $t1, $a1
andi $t2, $t1, 1
beq $t2, $zero, even_lp
subu $t1, $a1, 1
mul $t1, $t1, 4
addu $t1, $t1, $a0
lw $t2, ($t1)
b odd_lp
even_lp:
mul $t3, $t1, 4
addu $t3, $t3, $a0
lw $t4, ($t3)
subu $t1, $t1, 1
mul $t5, $t1, 4
addu $t5, $t5, $a0
lw $t6, ($t5)
addu $t6, $t6, $t4
div $t6, $t6, 2
odd_lp:
sw $t2, ($a2)   #median
sw $ra, 8($sp)
sw $fp, 4($fp)
sw $s0, 0($sp)
addu $sp, $sp, 12
jr $ra
.end stats

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote