0

我正在尝试创建一个函数,该函数根据浮点值返回字符值,例如:

|百分比 | 字母等级 | | 90.0 - 100.0 A | | 80.0 - 89.9 乙 | | 70.0 - 79.9 摄氏度 | | 60.0 - 69.9 D | | 低于 59.9 F |

这是我到目前为止所拥有的:

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; 

这是我在这里得到的输出:

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)

前 2、A 和 B 等级我能够让它工作,但任何低于 80 的东西,我都无法得到正确的字母,它一直终止程序。这背后的问题是什么?谢谢。

4

0 回答 0