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

Write a MIPS assembly language procedure, stats, that will find the minimum, med

ID: 3633745 • Letter: W

Question

Write a MIPS assembly language procedure, stats, that will find the minimum, median
maximum, sum, and average. You should find the minimum, median, and maximum a
list is sorted. The average should be calculated as a FLOATING POINT value.

MIPS assembly language procedure, stats, that will
# find the minimum, median, maximum, sum, and average of the list.
# Finds the minimum after the list is sorted (i.e, min=list(len-1)).
# The average is calculated as floating point value.

# -----
# Arguments:
# $a0 - starting address of the list
# $a1 - list length
# $a2 - addr of min
# $a3 - addr of med
# ($fp) - addr of max
# 4($fp) - addr of sum
# 8($fp) - addr of ave (float)

# Returns (via addresses):
# min
# med
# max
# sum
# average

I need specifically the average as a floating point. here is my sample that isnt working:

globl pv_stats
.ent pv_stats
pv_stats:



#
subu $sp, $sp, 4
sw $fp, ($sp)
addu $fp, $sp, 4

move $t9, $a1 # a1 has the length
move $t0, $a0
move $t1, $a2
move $t2, $a3
li $t8, 1

sumloop:
lw $t6, ($t0)
add $t5, $t5, $t6
add $t0, $t0, 4
sub $a1, $a1, 1
add $t8, $t8, 1
bgt $a1, 1, sumloop
lw $t7, 4($fp)
sw $t5, ($t7) # t5 does have the correct sum and $t8 has the length

l.s $f4, 8($fp)
div $t5, $t5, $t8

mtc1 $t5, $f2
cvt.s.s $f8, $f2
mtc1 $t8, $f10
cvt.s.s $f6, $f10
div.s $f12, $f8,$f10

s.s $f12, ($f4) # need to get the floating point average into 8($fp) !!

jr $ra
.end pv_stats



Explanation / Answer

MIPS assembly language procedure, stats, that will

# find the minimum, median, maximum, sum, and average of the list.
# Finds the minimum after the list is sorted (i.e, min=list(len-1)).
# The average is calculated as floating point value.

# -----
# Arguments:
# $a0 - starting address of the list
# $a1 - list length
# $a2 - addr of min
# $a3 - addr of med
# ($fp) - addr of max
# 4($fp) - addr of sum
# 8($fp) - addr of ave (float)

# Returns (via addresses):
# min
# med
# max
# sum
# average

.globl areaStats

.ent areaStats

areaStats:

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

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