Reputation: 21
I have an assembly program:
move eax, op1;
AND eax, 80000000h;
jz l1;
This program checks if op1
is positive or negative.
How does comparing eax
to 80000000h
check is op1
is negative or positive?
Upvotes: 2
Views: 1342
Reputation: 9071
Values in registers are stored in two's-complement format, and the highest bit corresponds to the negative sign. The constant 80000000h
corresponds to highest bit set in binary value of 1000 0000 0000 0000 0000 0000 0000 0000
. Applying and
with it to the register eax
results in non-zero if and only if the highest bit of eax
is set, that is, the number stored in eax
is negative. The conditional jump is not triggered in this case. It results in zero if the top bit is not set, that is, if the value is non-negative (0 or positive), and that triggers the jz
conditional jump.
Upvotes: 4