8085 program to find bit differences between two binary patterns.


Here we will see how to find the bit differences of two binary patterns using 8085.

Problem Statement

Two binary patterns are stored in locations 8030H and 8031H. Load them in registers A and B. Find out the bit positions where bits are differing and put these location numbers at locations starting from 8050H on words. (Bits are differing at those locations where 0 in A and 1 in B)

Discussion

To solve this problem, we are taking the numbers into A and B. Then initialize the C as counter with 08H, and the register L will keep tract the bit position, where A has 1 and B has 0. By rotating the numbers through carry we can check these criteria. Let us consider we are putting B5H (1011 0101) and E6H (1110 0110), then we can see that the position D1 and D6 are not same. So we are storing 1 and 6 into the memory.

Input

Address
Data


8030
B5
8031
E6


 

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
8000
21, 30, 80
START:
LXI H,8030H
Initialize pointer to the IN-BUFFER
8003
11, 50, 80
 
LXI D,8050H

Initialize pointer to the OUT-BUFFER
8006
7E
 
MOV A, M
Reading DATA from the IN-BUFFER and storing to the Reg. A and B
8007
23
 
INX H

 
8008
46
 
MOV B, M
 
8009
0E, 08
 
MVI C, 08H

Initialize count by the value 8
800B 
2E, 00
 
MVI L, 00H
Keep track about the bit position using Reg. L
800D 
1F
LOOP:
RAR

Rotate Accumulator right through carry
800E 
DA, 1C, 80
 
JC CHECK
Checking whether the D7 bit is on or off
8011
67
 
MOV H, A

Reg. H temporary holds the contents of Reg. A
8012
78
 
MOV A, B
The D7 bit of the contents of Reg. B is placed in the carry
8013
1F
 
RAR

 
8014
47
 
MOV B, A
Copy A to B
8015
7C
DCRM:
MOV A, H

Copy H to A
8016
2C
 
INR L
Incrementing the bit position by 1
8017
0D
 
DCR C

Decrement count until 0 is reached
8018
C2, 0D, 80
 
JNZ LOOP
 
801B 
76
 
HLT

Terminate the Program
801C 
67
CHECK:
MOV H, A
Reg. H temporary holds the contents of Reg. A
801D 
78
 
MOV A, B

The D7 bit of the contents of Reg. B is placed in the carry
801E 
1F
 
RAR
 
801F 
D2, 26, 80
 
JNC WRITE

Check whether the carry flag is set or not
8022
47
 
MOV B, A
Copy A to B
8023
C3, 15, 80
 
JMP DCRM

Jump unconditionally
8026
47
WRITE
MOV B, A
The matching bit pattern positions are
written to the OUT_BUFFER
8027
7D
 
MOV A, L

 
8028
12
 
STAX D
 
8029
13
 
INX D

Go to next location
802A 
C3, 15, 80
 
JMP DCRM
Jump unconditionally

 

Output

Address
Data


8050
01
8051
06


 

raja
Published on 17-Jun-2019 11:43:04
Advertisements