Reputation: 4006
I am comparing some input received from the user with some numbers, and the same jump is taken regardless of the compare.
User input is defined as so:
.data?
userInput REAL4 ?
And when I compare it I use:
cmp userInput, 18200
jge _tb0 ;This jump is always taken
However I have tested with userInput
being less than, equal, and great than 18200
but it still jumps to the same label.
I have just started learning assembly from this tutorial, which has been great so far, but doesn't have a lot of information and I am having trouble finding a good, detailed tutorial online so that I can learn what I am doing wrong.
UPDATE:
After reading a bit on using the FPU to do floating point math, I came up with the following code for variables:
.data?
userInput real4 ?
.const
tb0_max real4 18200.00
and the following code for comparing:
fld userInput
fcom tb0_max
jge _tb0
However I still get the same result as before, I jump to _tb0 regardless of the value given as user input
UPDATE 2:
After reading this on comparing with the FPU, I came across the following code which should, according to the article, allow me to move the compare states from the FPU to the CPU so that I can use a regular CPU compare instruction:
fld userInput
fcom tb0_max
fstsw ax
fwait
sahf
jge _tb0
However I am still having the same issue, the compare always result as the userInput being less than the constant 18200.00 regardless of userInput
Upvotes: 2
Views: 299
Reputation: 9899
Since you want to compare your single precission float (userInput) with an integer (18200) you could just temporarily store it as an integer and then perform the comparison:
.data?
userInput REAL4 ?
tempInteger dd ?
...
fld userInput
fistp tempInteger
cmp tempInteger, 18200
jge _tb0
Upvotes: 1
Reputation: 62048
cmp
itself works correctly. But you aren't using it correctly. REAL4
is a floating point type. cmp
works with integer operands only. Either use integers or learn how to compare floating point values.
Upvotes: 2