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

;variables

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


firstLine:

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

LoopTop:

inc  ax

mov  ax, usergrade
cmp  usergrade, 90
jb   LetterB


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

LetterB:
cmp  usergrade, 80
jb   LetterC

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

LetterC:
cmp  usergrade, 70
jb   LetterD

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

LetterD:
cmp  usergrade,60
jb   LetterF

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

LetterF:
mov  si, offset gradeF
mov  cx, gradeFLen
call putStrng

ExitOut:

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
    _start:

        call    MainPrompt
        push    0

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

    .Done:
        pop     rax
        call    ShowCount

        xor     rax, rax
        mov      al, 60
        syscall

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.