I have some calculation in asm in loop, it must be before Sum will be 3, but loop work all time and never ending. Here is mu code:
int main() {
float Sum=0;
int i=0;
int A=5;
int B=180;
int C=3;
_asm{
finit
m1:inc i
fldpi
fimul A
fimul i
fidiv B
fsin
fadd Sum
fstp Sum
fild Sum
ficom C
fstsw AX
sahf
jg m1
}
}
The FPU’s condition flags have completely different meanings than the condition flags in the EFLAGS register.
If
Sumis greater thanC, then theficomwill set the FPU condition flags to “C3=0, C2=0, C1=0”. When loaded into the CPU’s EFLAGS register (via.fstswandsahf) this becomes “ZF=0, PF=0, CF=0”. Thejginstruction will branch if “ZF=0” and “SF=0” – it won’t test the PF flag or the CF flag at all, but will test the irrelevant SF flag.Given that you’re comparing integers anyway; you should probably just do:
The alternative is to test the flags in AX directly. For example: