In: Computer Science
Assume that you have an array of 100 elements representing the grades students are stored in memory. Suppose the grades are in IEEE single precision format. Write a MIPS program to compute the average of the students grades and store the result in register $f0. Assume the array base address is stored in register $s0 and a floating point value of 100 is stored in memory with it address given in register $s2.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
code screenshot
copy to code
.data
grade: .float
90.2,81.8,64,58.2,78.3,88.7,57.6,83,89.7,75,76.2,69.6,87.7,75.7,87,86.9,52.3,95.6,88.9,85.4,91.9,96.2,78.9,90.5,99.5,85.7,99.6,71.8,99.6,80.9,96.8,83.9,81.1,96.8,53.3,66.6,69.3,53.7,92.3,77.8,70.3,77.3,53.8,63.3,94.3,89.8,68,58.6,85.5,80.1,88.7,72.4,92.6,64.2,62.6,88.6,61.7,66,60.3,56.2,56.6,72.8,60.8,54.9,60.3,80.1,93.5,80.6,56.5,75.3,86,87.9,98.3,56.1,92.3,89.4,62.9,55,80.1,86.1,80.8,59.9,79.1,92.9,51.1,91.9,52.6,62.4,52.7,77,86.1,74.4,98.8,57.3,99.4,80.4,97.9,82,94.6,65.9
size: .float 100.0
msg4: .asciiz "\nAverage of grades is : "
.text
.globl main
main:
#address of size
la $s2,size
#save address of array
la $s0,grade
#load size of 100
li $t1,100
#set index i=0
li $t0,0
add_loop:
#if i==100 jump to exit
beq $t0,$t1,addLoopExit
#get index of i
mul $t2,$t0,4
#get address of array[i]
add $t2,$t2,$s0
#load value from the address
l.s $f2,($t2)
#store number to sum
add.s $f0,$f0,$f2
#index++
addi $t0,$t0,1
#jump to loop
j add_loop
#break of loop
addLoopExit:
#load 100
l.s $f12,($s2)
#get average
div.s $f12,$f0,$f12
li $v0, 4
la $a0, msg4
syscall
#print float
li $v0,2
syscall
output