Reputation: 93
How to compare the values of SF (sign flag) and OF (overflow flag) flags in the x86 assembly?
After cmp
instruction, these flags are set, but I need to compare them in order to emulate the jl
instruction.
Upvotes: 3
Views: 773
Reputation: 29022
There are two major instructions testing the flags: the Jcc
instruction and the SETcc
instruction. Looking at both tables will give you a couple of instructions checking these two flags.
An example using the SETcc
instruction would be:
seto al ; Set byte to 1 if overflow (OF=1)
sets ah ; Set byte to 1 if sign (SF=1)
Now EAX
will contain the hexadecimal value
0101 if both flags have been set
0100 if sign has been set
0001 if overflow has been set
0000 if both flags have been cleared
Now you can compare AL
(overflow) to AH
(sign) with cmp al, ah
. The jl
instruction checks for difference (SF ≠ OF) so a jne
(no equal/zero) after this cmp
has the same effect as the original jl
.
Finally the whole code emulating a jl
is:
seto al
sets ah
cmp al, ah
jne lesser
Upvotes: 5