carry flag#
Carry Flag: It is triggered when the result of an operation is negative or exceeds the numerical limit. The general meaning is that if the calculation result exceeds the range, the CF flag will be triggered. 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 is for 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 represents the sign of the result, not whether the result is correct or not.
zero flag#
The ZF flag will be triggered under the following conditions: in internal comparison instructions that actually perform subtraction, when the two operands are the same; when addition or subtraction results in 0; when the subtraction result is 0.
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, you only need 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 parity | jump if not parity |
JPO | odd parity | jump if parity odd |
JS | sign | jump if sign |
JNS | not sign | jump if not sign |
JL/JNGE | sign and overflow | jump if less or not greater/equal |
JLE/JNG | z=1 or sign and overflow | jump if less or equal/not greater |
JG/JNLE | z=0 and sign and overflow | jump is greater/not less or equal |