I was assigned to write a program that asks the user to enter an integer test score between 0 and 100. The program should display the appropriate Letter grade. I have already written this code. Now I have to run in a loop so multiple test scores can be entered. and then accumulate a counter of the number of test scores. I have no idea how to even begin this part. Here is my code:

jmp firstLine


prompt db 'Enter a grade from 0 to 100: '
promptLen = $-prompt

usergrade dw ?

gradeA db 'Your Letter grade is an A '
gradeALen = $-gradeA

gradeB db 'Your Letter grade is a B '
gradeBLen = $-gradeB

gradeC db 'Your Letter grade is a C '
gradeCLen = $-gradeC

gradeD db 'Your Letter grade is a D '
gradeDLen = $-gradeD

gradeF db 'Your Letter grade is a F '
gradeFLen = $-gradeF


mov  si, offset prompt  ;prompts the user for grade and reads it in
mov  cx, promptLen
call putStrng
call getPos
mov  usergrade,ax   ;stores input to usergrade variable
call crlf

mov  bx, 0
mov  si, 0

mov  ax,0
mov  cx,5


inc  ax

mov  ax, usergrade
cmp  usergrade, 90
jb   LetterB

mov  si, offset gradeA
mov  cx, gradeALen
call putStrng
Loop ExitOut

cmp  usergrade, 80
jb   LetterC

mov  si, offset gradeB
mov  cx, gradeBLen
call putStrng
Loop ExitOut

cmp  usergrade, 70
jb   LetterD

mov  si, offset gradeC
mov  cx, gradeCLen
call putStrng
Loop ExitOut

cmp  usergrade,60
jb   LetterF

mov  si, offset gradeD
mov  cx, gradeDLen
call putStrng
Loop ExitOut

mov  si, offset gradeF
mov  cx, gradeFLen
call putStrng


mov  ah, 04c
int  021

include ioSubs.inc

What I usually do with any application or procedure is work from the outside in. So in your example I would have a title prompt that only shows up once and then a loop that would allow multiple entries.

        global _start
        section .text

        call    MainPrompt
        push    0

        call    GetScore
        jz      .Done
        inc     word [rsp]      ; Increments score counter.
        call    Display
        jmp     .L0

        pop     rax
        call    ShowCount

        xor     rax, rax
        mov      al, 60

The fact that this example is in 64 bit linux is inconsequentional as it's the flow of the loop that is important.

This article has been dead for over six months. Start a new discussion instead.