MIPS: determine if a list of tests passes

I am writing a MiPS program that will review a list of 15 tests. And it will be entered from the terminal. Well, the pass criterion is a score of 50. Outs to the terminal will include the grades in each category and the number of passing and unsuccessful students. with input and output hints ... Below is a program that I wrote, but it didn't work .... Please, I need .... I don't know if I'm doing it wrong ..

.globl main
.text

      

main: li $ t0, 0 #counter for passing la $ t1, pass #pointer for array pass
  li $ t2, 0 #counter for unsuccessful la $ t3, fail #pointer for array pass li $ t4, 0 # for the whole counter li $ t5, 0 li $ t6, 0

loop: li $ v0, 4 # system call for print line la $ a0, prompt line #load syscall

li $v0, 5           #system call for read integer
syscall             #read integer

bltu $v0, 50, else      #if $v0 < 50 branch to else (failing grade)
sw $v0, 0($t1)          #store word in pass array
addi $t1, $t1, 4        #t1 = t1 + 4 (increment pass pointer)
addi $t0, $t0, 1        #t0 = t0 + 1 (increment pass counter)
b l_end             #branch over else statement

      

more: sw $ v0, 0 ($ t3) #store word in fail array addi $ t3, $ t3, 4 # t3 = t3 + 4 (increment error pointer) addi $ t2, $ t2, 1 # t1 = t1 + 1 (increment counter counter)

l_end: addi $ t4, $ t4, 1 #increment total counter bltu $ t4, 15, loop #if t4 <= 15 branches per loop

amount of output

li $v0, 4           #system call for print string
la $a0, o_pasc          #load string
syscall             #output "Number of Passing Scores:

la $v0, 1           #system call for print integer
add $a0, $t0, 0         #load value of pass counter into $a0
syscall             #output value

li $v0, 4           #system call for print string
la $a0, o_fasc          #load string
syscall             #output "Number of Failing Scores: "

la $v0, 1           #system call for print string
add $a0, $t2, 0         #load value of fail counter into $a0
syscall             #output value

      

transfer results

li $v0, 4           #setup output   
la $a0, o_pass          #setup text
syscall             #output string o_pass

la $t1, pass            #load address of pass pointer to t1
lw $a0, 0($t1)          #load word at $t1 into $a0
li $v0, 1           #system call for print integer

      

loop_a: bleu $ t0, $ t5, lp_a_end #if t0 <= t5 branch to lp_a_end syscall #output single score

li $v0, 4           #system call for print string
la $a0, o_coma          #load string
syscall             #ouput comma and space

li $v0, 1           #setup output
addi $t1, $t1, 4        #move pointer down by 1 word
lw $a0, 0($t1)          #move word at pointer into $a0
addi $t5, $t5, 1        #add 1 to counter

b loop_a            #branch to top

      

lp_a_end:

withdrawal bad grades

la $t5, 0           #clear t5 (counter)
li $v0, 4           #setup output
la $a0, o_fail          #setup text
syscall             #output string o_fail

la $t3, fail            #load address for fail pointer into $t3
lw $a0, 0($t3)          #load word at mem addy $t3 into $a0
li $v0, 1           #system call for print integer

      

loop_b: bleu $ t2, $ t5, lp_b_end #if t2 <= t5 branch to lp_a_end syscall #output single score

li $v0, 4           #system call for print string
la $a0, o_coma          #load string
syscall             #output comma and space

li $v0, 1           #setup output
addi $t3, $t3, 4        #move pointer down by 1 word
lw $a0, 0($t3)          #load word from mem addy $t3 to $a0
addi $t5, $t5, 1        #add 1 to counter

b loop_b            #branch to top

      

lp_b_end:

end

li $v0, 4           #setup output
la $a0, o_brk           #setup text
syscall             #output line break

li $v0, 10          #loads 10 to $v0
syscall             #ends program

      

+1


source to share


1 answer


"Deja vu is usually a glitch in the matrix"

Pretty sure I've seen this around:

MIPS Program for Missed / Failed Test Grades

EDIT . Some tips: try to simplify. Build your program piece by piece. For example, try to avoid system calls, use hardcoded inputs to test your comparison logic. Then go to syscalls. Are you using arrays correctly? I saw that you keep two separate counters to index the array and keep the number of elements inside it. I think it is error prone. Perhaps you should use a counter to index the array (multiplying by 4). Follow the link, I will be happy to help if in any doubt.

I don't like the SPIM simulator. I know that many universities use it for their courses, but I think this is a mistake as it is a very limited environment.

ANOTHER CHANGE (per "popular" demand) : I've been reading your code for a while and I've noticed some things.

  • You are loading values ​​into registers for comparison to zero. Don't do this, use the $ zero register.

    li $ t5.0

    li $ t6.0

used in

bleu $t0,$t5,lp_a_end       #if t0 <= t5 branch to lp_a_end 

      

it should be

bleu $t0,$zero,lp_a_end

      



  • Using instructions

    bltu $ v0, 50, else #if $ v0 <50 to another (unsuccessful class)

branch instructions have two registers and a label. Do not register, do, mark

Should be:

   li   $t5,50
   bltu $v0,$t5,else

      

My guess is that you have a hard time over complicating system calls. Why do you think about your output when you can't make it work? In addition to this, once you start preparing for syscall, execute it. Don't put a branch instruction in the middle like in

        la $t3, fail                    #load address for fail pointer into $t3
        lw $a0, 0($t3)                  #load word at mem addy $t3 into $a0
        li $v0, 1        
loop_b: bleu $t2, $t5, lp_b_end         #if t2 <= t5 branch to lp_a_end 
        syscall                         #output single score

      

It's pretty confusing. You might want to try something like:

#Is there anything to print in the array? If not, goto lp_b_end
bleu $t2,$zero,lp_b_end

#Ok, we know we are not pointing at an invalid position of the array.       
la $t3, fail                    #load address for fail pointer into $t3
lw $a0, 0($t3)                  #load word at mem addy $t3 into $a0
li $v0, 1 
syscall

      

Finally, try to preserve the convention when using system calls. For example, use registers $ a0 and $ v0 for system calls only. Don't use them for anything else. If you read an integer in $ v0, move it to $ t0 before doing anything else.

That's all I can think of right now. As someone said in the bug report (Rob Kennedy), try asking your instructor why he is getting paid (I'm not your instructor, just a helping hand).

+3


source







All Articles