I am trying to create a function which returns a character value based on a floating-point value such as:
|Percentage | Letter Grade | | 90.0 - 100.0 A | | 80.0 - 89.9 B | | 70.0 - 79.9 C | | 60.0 - 69.9 D | | Below 59.9 F |
Here what I have so far:
program grade
#include("stdlib.hhf");
static
percentage: real32 :=0;
// Function grader //
procedure grader(percentage:real32); @nodisplay; @noframe;
static
returnAddress: dword;
cA : byte := $41; // A = hex 41
cB : byte := $42; // B = hex 42
cC : byte := $43; // C = hex 43
cD : byte := $44; // D = hex 44
cF : byte := $46; // F = hex 46
aGrade : real32 := 90.0;
bGrade : real32 := 80.0;
cGrade : real32 := 70.0;
dGrade : real32 := 60.0;
fGrade : real32 := 50.0;
begin grader;
pop(returnAddress);
pop(percentage);
push(returnAddress);
// Score for grade A
finit();
fld(percentage);
fld(st0);
fld(aGrade);
fld(st1);
fcomp();
fstsw(AX);
sahf();
setb(AL);
cmp(AL,0);
je gradeA;
// grade B score
fld(percentage);
fld(st0);
fld(bGrade);
fld(st1);
fcomp();
fstsw(AX);
sahf();
setb(AL);
cmp(AL,0);
je gradeB;
// grade C score
fld(percentage);
fld(st0);
fld(cGrade);
fld(st1);
fcomp();
fstsw(AX);
sahf();
setb(AL);
cmp(AL,0);
je gradeC;
// grade D score
fld(percentage); // st0
fld(st0);
fld(dGrade); // st4
fld(st1);
fcomp();
fstsw(AX);
sahf();
setbe(AL);
cmp(AL,0);
je gradeD;
// grade F score
fld(percentage); // st0
fld(st0);
fld(fGrade); // st5
fld(st1);
fcomp();
fstsw(AX);
sahf();
setbe(AL);
cmp(AL,0);
jne gradeF;
jmp finalGrade;
gradeA:
stdout.put("that's the grade: ");
stdout.putc(cA);
jmp finalGrade;
gradeB:
stdout.put("that's the grade: ");
stdout.putc(cB);
jmp finalGrade;
gradeC:
stdout.put("that's the grade: ");
stdout.putc(cC);
jmp finalGrade;
gradeD:
stdout.put("that's the grade: ");
stdout.putc(cD);
jmp finalGrade;
gradeF:
stdout.put("that's the grade: ");
stdout.putc(cF);
jmp finalGrade;
finalGrade:
ret();
end grader;
// Main //
begin grade;
stdout.put("Feed Me: ");
stdin.get(percentage);
push(percentage);
call grader;
stdout.newln();
end grade;
This is what I got for output here:
Feed Me: 90.0
that's the grade: A
Feed Me: 80.0
that's the grade: B
Feed Me: 70.0
(Exit Program)
Feed Me: 60.0
(Exit Program)
The first 2, A and B grades I was able to get it to work, but with anything below 80, I can't get the right correct letter and it keeps terminate the program. What is the issue behind this? Thanks.