Past exam question: 2082 Chaitra (Regular), Q4
Open in the Padhaiko appQuestion
Write a program for 8085 microprocessor to transfer eight-bit numbers from A000H to B000H if bit D6 is 1 and D2 is 0. Otherwise transfer data by complementing bit D1 and D5. Assume there are ten numbers.
Solution
Algorithm & Bit Testing Logic:
- Source block starting address:
A000H(accessed using HL pair). - Destination block starting address:
B000H(accessed using DE pair). - Total numbers to transfer: 10 (
0AHloaded into counter register C). - Condition testing:
- We need to test if bit D6 = 1 and bit D2 = 0.
- Bit D6 has positional weight 2^6 = 40H (0100 0000b).
- Bit D2 has positional weight 2^2 = 04H (0000 0100b).
- Mask for isolating D6 and D2 is 44H (0100 0100b).
- When a number is ANDed with 44H (
ANI 44H), if bit D6 is 1 and bit D2 is 0, the masked result must be exactly 40H.
- Complementing bits D1 and D5:
- Bit D5 = 20H (0010 0000b), Bit D1 = 02H (0000 0010b).
- Inverting specific bits without altering other bits is done by XORing with a mask containing 1s in those positions:
XOR Mask = 20H | 02H = 22H(0010 0010b). - Using
XRI 22Htoggles bits D1 and D5.
8085 Assembly Language Program:
LXI H, A000H ; HL = Source pointer
LXI D, B000H ; DE = Destination pointer
MVI C, 0AH ; C = 10 (loop counter)
LOOP: MOV A, M ; Load 8-bit number from source into A
MOV B, A ; Save original number in register B
; Test condition: D6 = 1 and D2 = 0
ANI 44H ; Mask bits D6 and D2 (0100 0100b)
CPI 40H ; Check if D6=1 and D2=0 (result == 40H)
JZ TRANSFER_DIR ; If condition met, transfer directly
; Otherwise: complement bits D1 and D5
MOV A, B ; Restore original number into A
XRI 22H ; Complement bit D5 (20H) and bit D1 (02H)
JMP STORE
TRANSFER_DIR:
MOV A, B ; Restore original number into A
STORE: STAX D ; Store byte at destination address [DE]
INX H ; Increment source pointer
INX D ; Increment destination pointer
DCR C ; Decrement loop counter
JNZ LOOP ; Repeat until all 10 numbers are processed
HLT ; Stop executionExecution Trace for Sample Data:
| Input Byte at A000H | Binary | Condition (D6=1, D2=0) | Action Taken | Result Stored at B000H |
|---|---|---|---|---|
40H | 0100 0000b | Met (D6=1, D2=0) | Transfer direct | 40H |
44H | 0100 0100b | Failed (D2=1) | XOR with 22H | 44H ^ 22H = 66H |
00H | 0000 0000b | Failed (D6=0) | XOR with 22H | 00H ^ 22H = 22H |
50H | 0101 0000b | Met (D6=1, D2=0) | Transfer direct | 50H |
Answer:
The program initializes source HL=A000H, destination DE=B000H, and counter C=0AH. For each byte, it isolates bits D6 and D2 with ANI 44H and CPI 40H. If equal, it stores the original byte directly; otherwise, it toggles bits D1 and D5 using XRI 22H before storing.