2076 10

CSC167 ยท 2076 ยท 5 marks

What is flag? Explain the flags that are present in 8085 microprocessor.

What is flag? Explain the flags that are present in 8085 microprocessor. [5]

MicroprocessorChapter 4: Assembly Language ProgrammingFlags

Quick answer

A flag is a single-bit flip-flop (1-bit register) that indicates the status or condition of the result stored in the accumulator after the completion of an arithmetic or logical operation. Flags are part of the Flag Register (also called the Program Status Word) inside the ALU. These flip-flops are set (1) or reset (0) according to the data condition of the result in the accumulator.

Flag in 8085 Microprocessor

What is a Flag?


Flags in 8085 Microprocessor

The 8085 microprocessor has five flags arranged in an 8-bit flag register. The five flags are:

1. Sign Flag (S)

  • After an arithmetic or logical operation, if the Most Significant Bit (D7) of the result is 1, the Sign flag is set (S = 1), indicating the result is negative.
  • If D7 = 0, the flag is reset (S = 0), indicating the result is positive.
  • Example: If result = 10000001 (in 2's complement, a negative number), S = 1.

2. Zero Flag (Z)

  • If the result of an operation is zero (00H), the Zero flag is set (Z = 1).
  • If the result is non-zero, the flag is reset (Z = 0).
  • Example: If 05H - 05H = 00H, then Z = 1.

3. Auxiliary Carry Flag (AC)

  • Also called the Half Carry Flag.
  • It is set (AC = 1) when there is a carry out from bit D3 to bit D4 (i.e., carry from the lower nibble to the upper nibble) during an arithmetic operation.
  • It is primarily used in BCD (Binary Coded Decimal) arithmetic operations (DAA instruction).
  • Example: If 0FH + 01H = 10H, a carry is generated from bit 3 to bit 4, so AC = 1.

4. Parity Flag (P)

  • After an operation, if the result has an even number of 1s, the Parity flag is set (P = 1) -- indicating even parity.
  • If the result has an odd number of 1s, the flag is reset (P = 0) -- indicating odd parity.
  • Example: Result = 00000011 (two 1s, even parity), so P = 1.

5. Carry Flag (CY)

  • The Carry flag is set (CY = 1) when an arithmetic operation results in a carry out from the MSB (bit D7) during addition, or a borrow during subtraction.
  • If there is no carry or borrow, it is reset (CY = 0).
  • Example: FFH + 01H = 100H; the carry out of bit 7 sets CY = 1.

Summary Table

FlagSymbolSet (= 1) When
SignSResult is negative (D7 = 1)
ZeroZResult is zero
Auxiliary CarryACCarry from D3 to D4
ParityPResult has even number of 1s
CarryCYCarry out from D7 (MSB)

These five flags together help the programmer to make conditional decisions (using conditional jump instructions like JZ, JC, JP, etc.) based on the outcome of operations.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.