I'm having difficulty translating C code that loops through an array of grades. The C code is as follows:
int A, B, C, D, F; // declare grade counters
int i; // declare loop counter
int N ; // Number of scores to analyze
A=0; B=0; C=0; D=0; F=0; // initialize grade counters
// Read in test scores into grades array?
// N will be equal to the number of grades
// assume N = 60
for (i=0; i<N; i++) {
if(scores[i] >= 90)
A = A + 1;
else if(scores[i] >= 80)
B = B + 1;
else if(scores[i] >= 70)
C = C + 1;
else if(scores[i] >= 60)
D = D + 1;
else
F = F + 1;
}
**Any help is appreciated. What I have so far is this: **
.data
data:
A: .word 0 #A=0
B: .word 0 #B=0
C: .word 0 #C=0
D: .word 0 #D=0
F: .word 0 #F=0
i: .word 0 #i=0
N: .word 60 #N=0
scores: .word 0:60 #scores array with 60 integers
.text
lw $s0, A #$s0=A=0
lw $s1, B #$s1=B=0
lw $s2, C #$s2=C=0
lw $s3, D #$s3=D=0
lw $s4, F #$s4=F=0
lw $s5, i #$s5=i=0
lw $s6, N #$s6=N=60
lw $t1, 90
lw $t2, 80
lw $t3, 70
lw $t4, 60
lw $t5, scores
for:
blt $s5, $s6, if
li $v0, 4
if:
bge $s5($scores), $t1, inc1
inc1: addi $s0, $s0, 1
j for
elseif1:
bge $s5(scores), $t2, inc2
inc2: addi $s1, $s1, 1
j for
elseif2:
bge $s5(scores), $t3, inc3
inc3: addi $s2, $s2, 1
j for
elseif3:
bge $s5(scores), $t4, inc4
inc4: addi $s3, $s3, 1
j for
else:
addi $s4, $s4, 1
j exit
exit: