- Asked 3/14
- 2073 Magh · 1+2+5 marks
- 2073 Bhadra · 4 marks
- 2072 Magh · 1+2+5 marks
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)
| Flag | Set (=1) when | Reset (=0) when |
|---|---|---|
| S Sign | Bit D7 of result is 1 (negative) | D7 is 0 |
| Z Zero | Result is 00H | Result is non-zero |
| AC Auxiliary carry | Carry from bit D3 to D4 | No such carry |
| P Parity | Result has an even number of 1s | Odd number of 1s |
| CY Carry | Carry 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)
Related questions
- Classification of 8085 instructions · Microprocessor, chapter 2
- RST instructions in 8085 · Microprocessor, chapter 2
- PC and SP in CALL, RET, PUSH, POP · Microprocessor, chapter 2
- Data manipulation: logical and bit instructions · Computer Organization and Architecture, chapter 2 · asked 2×
- Arithmetic versus logical IF · Computer Programming, chapter 11 · asked 3×
- Pile capacity in sand, group effect, load test · Foundation Engineering, chapter 8
- Need of logical clock synchronization · Distributed System, chapter 5