I'm working on a MASM32 project, using the x87 instruction set. I want to compare two floating point numbers and print out a message telling the result of the comparison. My program is:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include c:\masm32\include\masm32rt.inc
.data
_a DD ?
_b DD ?
FP_11_ DD 11.
FP_10_ DD 10.
.code
start:
MOV ebx, FP_10_
MOV _a, ebx
FLD _a
FCOM FP_11_
fstsw ax
sahf
JGE label5
print "less", 13, 10, 0
JMP label6
label5:
print "greater", 13, 10, 0
label6:
jmp end_program
end_program:
invoke ExitProcess, 0
end start
The expected result is "less" but i'm getting "greater". So, my question is: how can I compare correctly two FP numbers by <=
, >=
, <
, >
, ==
and <>
using the x87 instructions?.