Reputation: 35
Sorry for the elementary question.
In assembly is it acceptable to compare two floating points stored at different (fixed) memory locations without loading them into the stack? Do I need to use anything besides CMP and JLE?
E.g. Memory address [A] currently equals 95, memory address [B] equals [90]. I want to do a jump if [A] is less than or equal to 90. Is the following sufficient?
CMP DWORD PTR [A], CMP DWORD PTR [B]
JLE [Another address]
Upvotes: 0
Views: 137
Reputation: 28828
If both floats are positive, and you don't care about issues like NAN:
mov eax,[a]
cmp eax,[b]
jbe ...
If either float can be negative, but not negative zero (080000000h):
mov eax,[a]
cmp eax,[b]
mov ecx,eax
sar ecx,31
or ecx,080000000h
xor eax,ecx
mov ecx,ebx
sar ecx,31
or ecx,080000000h
xor ebx,ecx
cmp eax,ebx
jbe ...
Negative 0 will end up 07fffffffh, less than positive 0 which ends up 080000000h. If this is an issue, the code would need to be modified.
Upvotes: 2