In: Computer Science
Lab-3C Pre-test Loop
Write a MIPS program to count the number of students who failed in a course. The final grades are given in an array. The fail grade is 60.
Example: Array and Output
.data
NoOfStudents: 10
Values: 60 70 80 50 90 80 55 90 80 70
Output:
2 students failed
.data
NoOfStudents: 12
Values: 60 70 80 50 90 80 55 90 80 70 55 80
Output:
3 students failed
Given below is the code for the question. Please do rate the answer if it helped. Thank you.
.data
numStudents: .word 12
grades: .word 60 70 80 50 90 80 55 90 80 70 55 80
msg: .asciiz " students failed"
.text
   lw $t0, numStudents #read the size
   li $t1, 0 #initialize loop counter
   la $t2, grades #get address of first array
element
   li $t3, 0 #no. of student who failed
  
loop:
   bge $t1, $t0, endloop
   lw $t4, ($t2) #read the current number
   bge $t4, 60, next #not fail student
   add $t3, $t3, 1
next:
   add $t1, $t1, 1 #increment loop counter
   add $t2, $t2, 4 #next element address
   b loop
endloop:
   #print results
  
   #print int
   move $a0, $t3
   li $v0, 1
   syscall
   #print string
   li $v0, 4
   la $a0, msg
   syscall
  
   #exit
   li $v0, 10
   syscall
output
-----
3 students failed
-- program is finished running --