Flags Affected by Addition and Subtraction
The IA-32 provides instructions that are able to use the status flags to
- check the outcome of arithmetic operations, and
- alter the sequence in which the program is executed; for instance, the condition
Z
equal to logic 0 could be tested for to initiate a jump to another part of the program.
This is called jump on not zero: jnz
.
The flag values below can be found from the command call DumpRegs
:
- Zero flag:
It is set when result of an arithmetic operation is zero.
- Sign flag:
It is set when the result of a signed arithmetic operation is negative.
- Carry flag:
Two cases are
- Addition:
When adding two unsigned integers, the
Carry
flag is a copy of the carry out of the MSB (most significant bit) of the destination operand.
- Subtraction:
The
Carry
flag is set when a larger unsigned integer is subtracted from a smaller one.
- Overflow flag (signed arithmetic):
It is set when the result of a signed arithmetic operation overflows or underflows the destination operand.
- Parity flag:
It counts the number of 1 bits in the least significant byte of the destination operand.
It is set when the least significant byte of the destination has an even number of 1 bits.
- Auxiliary carry flag:
It is set when a 1 bit carries out of position 3 in the least significant byte of the destination operand.
†The CPU does not know whether an arithmetic operation is signed or unsigned.
The programmers decide whether the operation is signed or unsigned and which flags to interpret and which to ignore.