The program should be built using MIPS Heres what I have so

The program should be built using MIPS

Heres what I have so far, it says the average is 0 when I run it.


   .text
   .globl main
  

main:
li $t0,0
li $t1,0
li $t2,0
li $t3,0
li $t4,-1
la $a0,scores

evaluate:
   lw $t2,0($a0)
   beq $t2,$t4,compute
   slti $t3,$t2,0
   bne $t3,$t2,badnum
   slti $t3,$t2,101
   beq $t3, $zero, badnum
  
   beq $t2,$t4,compute
   add $t1,$t1,$t2
   addi $t0,$t0,1
   addi $a0,$a0,4
   j evaluate
  
badnum: addi $a0,$a0,4
   j evaluate
  
compute:
   li $v0,4  
   la $a0,avgStr
   syscall
  
   div $t1,$t0
   mflo $v0
   move $a0,$v0
   li $v0,1
   syscall
  
.data
scores: .word 95,92,85,100,81,90,75,99,82,79,-1 #list of test scores
avgStr: .asciiz \"The average is :\"

# write and debug a program that will compute average of list of midterm test scores and return #in $v0. # The list consists of scores from 0 through 100 and is terminated with -1. # sum = count = 0; # sum += *score; # count += 1; # score += 4; # average = sum/count; # # Inputs : # $a0 - address of list of scores # Outputs: # $v0 - returns the average of the test scores or -1. # Locals: # $t0 = score counter # $tl = score sum # $t2 = temp for score # $t3 = temp # $t4 = holds terminator marker, -1 # #This is the data (scores) section # data #scores: .word 95, 92, 85, 100, 81, 90, 75, 99, 82, 79, -1

Solution

  .text
   .globl main
  

main:
li $t0,0
li $t1,0
li $t2,0
li $t3,0
li $t4,-1
la $a0,scores

evaluate:
   lw $t2,0($a0)
   beq $t2,$t4,compute
   slti $t3,$t2,0
   bne $t3,$t2,badnum
   slti $t3,$t2,101
   beq $t3, $zero, badnum
  
   beq $t2,$t4,compute
   add $t1,$t1,$t2
   addi $t0,$t0,1
   addi $a0,$a0,4
   j evaluate
  
badnum: addi $a0,$a0,4
   j evaluate
  
compute:
   li $v0,4  
   la $a0,avgStr
   syscall
  
   div $t1,$t0
   mflo $v0
   move $a0,$v0
   li $v0,1
   syscall
  
.data
scores: .word 95,92,85,100,81,90,75,99,82,79,-1 #list of test scores
avgStr: .asciiz \"The average is :\"

The program should be built using MIPS Heres what I have so far, it says the average is 0 when I run it. .text .globl main main: li $t0,0 li $t1,0 li $t2,0 li $
The program should be built using MIPS Heres what I have so far, it says the average is 0 when I run it. .text .globl main main: li $t0,0 li $t1,0 li $t2,0 li $

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site