Skip to main content

8085 flags and their effect

Short answer

Flags are 1-bit status flip-flops in the 8085: Sign, Zero, Auxiliary Carry, Parity, Carry. Arithmetic instructions (ADD, SUB) affect all five; logical instructions set CY=0 and AC=0 or 1 depending on operation, while S,Z,P reflect result; XRA A clears A and CY.

What is flag? Discuss about 8085 associated flags. Along with suitable examples show how these flags are affected by arithmetic and logical group of instructions.

Flag

A flag is a 1-bit flip-flop which shows a condition produced by the last arithmetic or logical operation. The flags are stored in the 8-bit flag register, and conditional jump/call/return instructions test them.

8085 flags

 D7  D6  D5  D4  D3  D2  D1  D0
 S   Z   X   AC  X   P   X   CY      (X = undefined)
FlagSet (=1) whenReset (=0) when
S SignBit D7 of result is 1 (negative)D7 is 0
Z ZeroResult is 00HResult is non-zero
AC Auxiliary carryCarry from bit D3 to D4No such carry
P ParityResult has an even number of 1sOdd number of 1s
CY CarryCarry out from D7 (or borrow in subtraction)No carry/borrow

Effect of arithmetic group (ADD, ADI, SUB, CMP, etc.)

All five flags are affected.

Example 1: A = 9AH, ADI 76H

  1001 1010   (9AH)
+ 0111 0110   (76H)
= 1 0001 0000  -> A = 10H

CY = 1 (carry out), AC = 1 (A+6 = 10H, carry from low nibble), S = 0, Z = 0, P = 0 (one 1 only, odd).

Example 2: A = 80H, ADI 80H gives A = 00H: CY = 1, Z = 1, P = 1, S = 0, AC = 0.

Example 3: A = 7FH, ADI 01H gives A = 80H: S = 1, AC = 1, CY = 0, Z = 0, P = 0.

INR and DCR affect all flags except CY. INX, DCX, LXI, MOV, PUSH, POP affect no flags. DAD affects only CY.

Effect of logical group (ANA, ANI, ORA, ORI, XRA, XRI, CMA, CMP)

  • ANA / ANI: CY = 0 and AC = 1 always; S, Z, P depend on the result.
  • ORA / ORI / XRA / XRI: CY = 0 and AC = 0; S, Z, P depend on the result.
  • CMA: no flags change. CMP: flags set as for subtraction (Z = 1 if equal, CY = 1 if A < operand).
  • Rotate instructions (RLC, RRC, RAL, RAR) affect only CY.

Example 4: A = F0H, B = 0FH, ANA B gives A = 00H: Z = 1, P = 1, S = 0, CY = 0, AC = 1.

Example 5: A = 85H, ORA A gives A = 85H: S = 1, Z = 0, P = 0 (three 1s), CY = 0, AC = 0.

Example 6: XRA A clears A: A = 00H, Z = 1, P = 1, CY = 0, AC = 0 (a common way to clear A and CY).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →