my assignment involves creating a grading program.
my program must accept a number from the user within the 0 - 100 range and
return the corresponding letter grade based on this rubric:
90 to 100 = A
80 to 89 = B
70 to 79 = C
60 to 69 = D
0 to 59 = F
as of now. my code is able to accept the user input and output it back to the console. now i would like to compare the input received form the user and return the
corresponding letter grade along with the number entered.
i have absolutely not a clue whether to use an array or other method, but my array
attempts have led to disaterous seg faults left and right.
here is the generated code thus far:
sys_exit equ 1
sys_read equ 3
sys_write equ 4
stdin equ 0
stdout equ 1
stderr equ 3
SECTION .data
szName db "Enter your Score to Receive the Letter Grade Equivalent: "
Name_Len equ $-szName
szHello db " ", 0
Hello_Len equ $-szHello
SECTION .bss
lpBuffer resb 7
Buf_Len equ $-lpBuffer
Buf resb 1
SECTION .text
global _start
_start:
nop
mov ecx, szName
mov edx, Name_Len
call DisplayText
mov ecx, lpBuffer
mov edx, Buf_Len
call ReadText
push eax
cmp eax, Buf_Len
jl Good
cmp byte [ecx + edx - 1], 10
je Good
mov byte [ecx + edx - 1], 10
mov ebp, 0
call ClearTerminal
Good:
mov ecx, szHello
mov edx, Hello_Len
call DisplayText
pop edx
mov ecx, lpBuffer
call DisplayText
jmp Exit
ClearTerminal:
inc ebp
mov edx, 1
mov ecx, Buf
mov ebx, stdin
mov eax, sys_read
int 80h
cmp [Buf], 30h
Jb ClearTerminal
cmp [Buf], 39h
Ja ClearTerminal
cmp byte [ecx + edx - 1], 10
jne ClearTerminal
ret
DisplayText:
mov eax, sys_write
mov ebx, stdout
int 80H
ret
ReadText:
mov ebx, stdin
mov eax, sys_read
int 80H
ret
GradeRubric:
Exit:
mov eax, sys_exit
xor ebx, ebx
int 80H
nop