Note that there are some explanatory texts on larger screens.

plurals
  1. POIf statements, logical AND, comparisons
    primarykey
    data
    text
    <p>I'm new to MIPS assembly language. Just started to learn. I've got this problem where I have to display a letter grade for the test score that the user inputs. I've done this so far, but I cannot get it to work. I always keep getting invalid or sometimes the program ends or gives a D.</p> <p>It is assumed:</p> <pre><code>Score Range Letter Grade 90 to 100 A 80 to 89 B 70 to 79 C 60 to 69 D 0 to 59 F </code></pre> <p>Please help me figure out what I'm doing wrong and correct my code!</p> <pre><code>.data prompt: .asciiz "Enter a test score [0 to 100] or -1 to stop: " invalidPrompt: .asciiz "Invalid \n" A: .asciiz "A \n" B: .asciiz "B \n" C: .asciiz "C \n" D: .asciiz "D \n" F: .asciiz "F \n" .globl main .text main: li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall #move $a1, $v0 beq $v0, -1, end # -1 to stop checkA: bge $v0, 90, checkB ble $v0, 100, checkB li $v0, 4 la $a0, A syscall # j main checkB: bge $v0, 80, checkC ble $v0, 89, checkC li $v0, 4 la $a0, B syscall # j main checkC: bge $v0, 70, checkD ble $v0, 79, checkD li $v0, 4 la $a0, C syscall # j main checkD: bge $v0, 60, checkF ble $v0, 69, checkF li $v0, 4 la $a0, D syscall # j main checkF: #bge $v0, 0, invalid ble $v0, 59, end li $v0, 4 la $a0, D syscall # j main invalid: blt $v0, 0, end bge $v0, 100, end li $v0, 4 la $a0, invalidPrompt syscall # j main j main end: #--- TERMINATE --- li $v0, 10 # terminate program run and syscall # return control to the OS. </code></pre> <p>The second part of the problem is I have to display the number of A's, B's and so on after user enters -1. How can I go about this? I know I have to store the count of each grade when true in a separate register and keep incrementing but not sure how this is done.</p> <p>Edit: I am using MARS 4.1 tool on Windows 7.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload