Upon execution of the following routine, find the value stored at location 00FFH.
MVI B, 0FH
MVI C, ABH
MOV A, C
ADD B
SBI 02H
STA 00FFH
Also write the status of each flag after completion of execution.
10 marks · directive: Find
The core of a good answer
Location 00FFH holds B8H (1011 1000); after SBI 02H the flags are S = 1, Z = 0, P = 1, CY = 0, and AC = 1 when the subtraction is taken as two's complement addition.
An outline written by upsc.help, not an official UPSC answer; every fact checked by a separate review. How we work
What the question asks
The question tests tracing 8085 instructions and knowing which instructions affect flags. MVI, MOV and STA do not affect any flag, so the final flag status is decided by SBI 02H alone (ADD B sets the borrow input CY used by SBI). Each flag must be stated with its reason.
Answer outline
Introduction
Trace register contents instruction by instruction, then evaluate the five flags (S, Z, AC, P, CY) after the last flag-affecting instruction, SBI 02H.
Step 1: Load registers
- MVI B, 0FH: B = 0FH
- MVI C, ABH: C = ABH
- MOV A, C: A = ABH (no flags affected by MVI or MOV)
Step 2: ADD B
- A = ABH + 0FH = BAH (1010 1011 + 0000 1111 = 1011 1010)
- No carry out of bit 7, so CY = 0
- Lower nibbles B + F = 1AH, so AC = 1 after ADD
- BAH has five 1s, so P = 0 after ADD; S = 1, Z = 0
Step 3: SBI 02H (A ← A − 02H − CY)
- CY = 0 from ADD, so A = BAH − 02H − 0 = B8H
- In the 8085 this is A + 2's complement of (02H + CY): BAH + FEH = 1B8H; the carry out is complemented to give CY = 0 (no borrow)
Step 4: STA 00FFH
- Content of A, B8H, is stored at memory location 00FFH; STA does not alter flags
Step 5: Flag status after SBI 02H
- S = 1: bit 7 of B8H (1011 1000) is 1
- Z = 0: result is not zero
- P = 1: B8H has four 1s (even parity)
- CY = 0: no borrow, since BAH > 02H
- AC = 1, taking the 8085 subtraction as two's complement addition: the lower nibbles give AH + EH = 18H, a carry out of bit 3
Conclusion
Memory location 00FFH = B8H. Flag register: S = 1, Z = 0, AC = 1, P = 1, CY = 0. Check: 171 + 15 − 2 = 184 decimal = B8H.
Examples and data to cite
- Decimal check: ABH = 171, 0FH = 15, sum 186 = BAH, minus 2 gives 184 = B8H.
- Of the instructions in this routine, ADD B and SBI 02H are arithmetic instructions, whose results the flags indicate.
Facts to remember
- The 8085 flags are sign (S), zero (Z), auxiliary carry (AC), parity (P) and carry (CY); S copies bit 7 of the result.
- SBI data subtracts the 8-bit data and the carry flag from the accumulator: A ← A − data − CY.
- In subtraction the carry flag is set when a borrow is required.
- Parity flag P = 1 for an even number of 1s in the result.
- STA 16-bit address stores the accumulator directly at that memory address.