Carry Flag: The Carry Flag (CF register) is triggered when the result of an operation is negative or exceeds the numerical limit. It means that if the calculation result exceeds the range, the CF flag will be triggered. Similarly, if the result of subtracting two unsigned numbers is negative, the CF flag will also be triggered.
Overflow Flag: The OF flag is similar to the CF flag, but it applies to signed numbers. It is triggered when there is an error in the calculation of signed numbers.
Signed Flag: The SF flag is triggered if the result of any operation is a negative number. SF only indicates the sign of the result, not whether the result is correct or not.
Zero Flag: The ZF flag is triggered under the following conditions: in internal comparison instructions that actually perform subtraction, when both operands are the same; when an increment or decrement operation results in zero; when the result of subtraction is zero.
Conditional Jump and Flags: When two operands are the same, the JZ instruction will perform a jump. If the first unsigned operand is smaller than the second, the JB instruction will perform a jump. If the first signed operand is smaller than the second, the JL instruction will perform a jump. Generally, it is only necessary to look at the third column of the unsigned conditional jump and signed conditional jump tables.
asm | condition | operation |
---|---|---|
JA | z=0 and c=0 | jump if above |
JAE | c=0 | jump if above or equal |
JB | c=1 | jump if below |
JBE | z=1 or c=1 | jump if below or equal |
JC | c=1 | jump if carry |
JECXZ | ecx=0 | jump if ecx is 0 |
JE | z=1 | jump if equal |
JZ | z=1 | jump if zero |
JNE | z=0 | jump if not equal |
JNZ | z=0 | jump if not zero |
JO | overflow | jump if overflow |
JP | even parity | jump if parity |
JPE | even parity | jump if parity even |
JNP | not even parity | jump if not parity |
JPO | odd parity | jump if parity odd |
JS | sign=1 | jump if sign |
JNS | sign=0 | jump if not sign |
JL/JNGE | sign=overflow | jump if less or not greater/equal |
JLE/JNG | z=1 or sign=overflow | jump if less or equal/not greater |
JG/JNLE | z=0 and sign=overflow | jump is greater/not less or equal |