- Individual bits control the action or represent the status of the processor
- Control flags (TF, IF, DF)
- Determine how the processor responds to certain situations
- Status flags (CF, PF, AF, ZF, SF, OF)
- Set to represent the result of certain operations
- Used to control conditional jump instructions

Bit |
Name |
Symbol |

0 | Carry flag | cf |

2 | Parity flag | pf |

4 | Auxiliary carry flag | af |

6 | Zero flag | zf |

7 | Sign flag | sf |

8 | Trace flag | tf |

9 | Interrupt flag | if |

10 | Direction flag | df |

11 | Overflow flag | of |

**Control Flags**

- DF - Direction flag
- STD: direction = down
- CLD: direction = up
- IF - Interrupt enable
- STI: enable external interrupts
- CLI: disable maskable external interrupts
- TF - Trace flag
- Interrupt 1 after executing instruction, if set

- Carry
- carry or borrow at MSB in add or subtract
- last bit shifted out
- Parity
- low byte of result has even parity
- Auxiliary
- carry or borrow at bit 3
- Zero
- result is 0
- Sign
- result is negative
- Overflow
- signed overflow occurred during add or subtract

- CF = 1 if there is a carry out from the msb (most significant bit) on addition, or there is a borrow into the msb on subtraction
- CF = 0 otherwise
- CF is also affected by shift and rotate instructions

- PF = 1 if the low byte of a result has an even number of one bits (even parity)
- PF = 0 otherwise (odd parity)

- AF = 1 if there is a carry out from bit 3 on addition, or there is a borrow into the bit 3 on subtraction
- AF = 0 otherwise
- AF is used in binary-coded decimal (BCD) operations

- ZF = 1 for a zero result
- ZF = 0 for a non-zero result

- SF = 1 if the msb of a result is 1; it means the result is negative if you are giving a signed interpretation
- SF = 0 if the msb is 0

- OF = 1 if signed overflow occurred
- OF = 0 otherwise

- Can only occur when adding numbers of the same sign (subtracting with different signs)
- Detected when carry into MSB is not equal to carry out of MSB
- Easily detected because this implies the result has a different sign than the sign of the operands
- Programs can ignore the Flags!

*Carry in = 0, Carry out = 1*
*Neg+Neg=Pos*
*Signed overflow occurred*
*OF = 1 (set)*

** 00110110**
__+ 01100011__** 10011001**

*Carry in = 1, Carry out = 0*
*Pos+Pos=Neg*
*Signed overflow occurred*
*OF = 1 (set)*

*Carry in = 0, Carry out = 0*
*Neg+Pos=Neg*
*No Signed overflow occurred*
*OF = 0 (clear)*

** 10010110**
__+ 11110011__** 10001001**

*Carry in = 1, Carry out = 1*
*Neg+Neg=Neg*
*No Signed overflow occurred*
*OF = 0 (clear)*

- The carry flag is used to indicate if an unsigned operation overflowed
- The processor only adds or subtracts - it does not care if the data is signed or unsigned!

*Carry out = 1*
*Unsigned overflow occurred*
*CF = 1 (set)*

- MOV and XCHG - no flags are changed
- ADD and SUB - all flags affected
- INC and DEC - all except CF
- NEG - all flags affected
- CF=0 only if value is 0
- OF=1 only if value is -MAXINT
- 80h or 8000h