CSC167 ยท 2080 ยท 5 marks
What is flag? Explain all the flags present in 8085 microprocessor.
What is flag? Explain all the flags present in 8085 microprocessor. [5]
Quick answer
A flag is a single-bit flip-flop (1-bit register) that indicates the status of the accumulator or other registers after the completion of an arithmetic or logical operation. These flip-flops are set (1) or reset (0) according to the data condition of the result stored in the accumulator.
Flags in 8085 Microprocessor
What is a Flag?
The flag register (also called the status register or F register) is an 8-bit register, but only 5 bits are used as flags in the 8085 microprocessor.
The 5 Flags of 8085 Microprocessor
The flag register layout is as follows:
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|
| S | Z | -- | AC | -- | P | -- | CY |
1. Sign Flag (S) -- Bit 7
- Set to 1 if the MSB (bit 7) of the result is 1, indicating the result is negative.
- Reset to 0 if the result is positive (MSB = 0).
- Used in signed number arithmetic.
Example: If result = 10000001 (negative in 2's complement), S = 1.
2. Zero Flag (Z) -- Bit 6
- Set to 1 if the result of the operation is zero.
- Reset to 0 if the result is non-zero.
Example: If 05H - 05H = 00H, then Z = 1.
3. Auxiliary Carry Flag (AC) -- Bit 4
- Set to 1 if there is a carry out from bit 3 to bit 4 (i.e., carry from the lower nibble to the upper nibble).
- Primarily used in BCD (Binary Coded Decimal) arithmetic operations.
Example: If lower nibble addition produces a carry to bit 4, AC = 1.
4. Parity Flag (P) -- Bit 2
- Set to 1 if the result contains an even number of 1s (even parity).
- Reset to 0 if the result contains an odd number of 1s (odd parity).
Example: If result = 00000011 (two 1s -- even), then P = 1.
5. Carry Flag (CY) -- Bit 0
- Set to 1 if there is a carry out from the MSB (bit 7) during addition, or a borrow during subtraction.
- Reset to 0 if there is no carry or borrow.
Example: If FFH + 01H = 100H (carry out), then CY = 1.
Summary Table
| Flag | Symbol | Bit Position | Set When |
|---|---|---|---|
| Sign | S | 7 | Result is negative (MSB = 1) |
| Zero | Z | 6 | Result is zero |
| Auxiliary Carry | AC | 4 | Carry from bit 3 to bit 4 |
| Parity | P | 2 | Result has even number of 1s |
| Carry | CY | 0 | Carry out from MSB |
These five flags together help the programmer make conditional decisions (using conditional jump instructions) based on the outcome of arithmetic and logical operations.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.