Past exam question: 2081 Chaitra (Regular), Q4(b)
Open in the Padhaiko appQuestion
Explain flags in 8086 Microprocessor.
Solution
Flag Register Bit Organization: The 8086 Flag Register is a 16-bit register containing 9 active flags (6 Status/Condition Flags and 3 Control Flags) and 7 undefined bits:
| Bit | D15–D12 | D11 | D10 | D9 | D8 | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Flag | Reserved | OF | DF | IF | TF | SF | ZF | Res | AF | Res | PF | Res | CF |
Status Flags (Condition Flags): Status flags are updated automatically by the ALU to reflect properties of the operation result:
- CF (Carry Flag): Set to 1 if an arithmetic addition generates a carry out of the MSB (bit 7 for 8-bit, bit 15 for 16-bit) or subtraction generates a borrow; reset to 0 otherwise.
- PF (Parity Flag): Set to 1 if the lower 8 bits of the result contain an even number of 1s (even parity); reset to 0 for odd parity.
- AF (Auxiliary Carry Flag): Set to 1 if a carry occurs from bit 3 into bit 4 during BCD addition or subtraction.
- ZF (Zero Flag): Set to 1 if the result of an arithmetic or logical operation is zero (0000H); reset to 0 if non-zero.
- SF (Sign Flag): Reflects the MSB of the result (bit 7 for 8-bit, bit 15 for 16-bit). Set to 1 for negative numbers in two's complement; reset to 0 for positive.
- OF (Overflow Flag): Set to 1 if a signed arithmetic operation produces a result that exceeds the capacity of the destination register (signed overflow); reset to 0 otherwise.
Control Flags: Control flags are manipulated by software instructions to govern processor execution modes:
- TF (Trap Flag): When set to 1 by a debugger, puts the processor into single-step execution mode, generating internal Type 1 interrupt after each instruction.
- IF (Interrupt Enable Flag): When set to 1 (
STI), the CPU responds to maskable hardware interrupts on theINTRpin. When cleared (CLI),INTRis ignored. - DF (Direction Flag): Controls auto-increment/decrement of SI and DI during string operations (
MOVS,CMPS). When DF = 0 (CLD), pointers auto-increment (process string forward); when DF = 1 (STD), pointers auto-decrement (backward).
Answer:
The 8086 has a 16-bit flag register with 9 active flags: 6 status flags (CF, PF, AF, ZF, SF, OF) indicating ALU operation results, and 3 control flags (TF for single-stepping, IF for enabling INTR, and DF for auto-incrementing/decrementing string pointers).