x87-Learner
x87-Learner

Reputation: 35

Can I compare two floats without loading them on the x87 stack?

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

Answers (1)

rcgldr
rcgldr

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

Related Questions