Jump's based on comparing signed integers use the Zero, Sign, and Overflow flag to determine the relationship between operands. After CMP
with two signed operands, there are three possible scenario's:
ZF = 1
- Destination = SourceSF = OF
- Destination > SourceSF != OF
- Destination < Source
I'm having trouble understanding scenario 2 and 3. I've worked through the possible combinations and see that they do work - but I still can't figure out why they work.
Can anyone explain why a comparison of the Sign and Overflow flags reflects signed integer relationships?
Edit:
There seems to be some understanding regarding what I'm asking. Jumps based on signed comparisons utilize the Zero, Sign, and Carry flag - these include JG
, JL
, and so on.
For example:
mov al, 1
cmp al, -1
jg isGreater
isGreater:
The jump is taken because Overflow flag = Sign Flag (both are 0), indicating in terms of signed comparison, the destination operand is larger than the source.
If the Overflow flag was set to 1 and the Sign flag set to 0, that would indicate the destination is smaller.
My questions is - I just can't seem to wrap my head around WHY this actually works.