8085 program to find the element that appears once


In this program we will see how to find a number who appears only once in an array of elements.

Problem Statement

Write 8085 Assembly language program to find a number who appears only once in an array of elements. The size of the array is stored at location F100; the numbers are stored from memory location F101 onwards. The result will be stored at F150.

Discussion

The logic behind this problem is simple. Though it may find some wrong results in some cases. It can find the number if there is only one number which is appeared once, and rest of the numbers are appeared even number of times.

We are doing the XOR operation on the numbers. If one number is already present, and we XOR it with the same number it will be 0. So if the same numbers appeared even number of times we can get 0. After cumulative XOR operations, the final number will be that number whose frequency is one.

Input

Address
Data

.

.

.

.

.

.

F100
05
F101
0C
F102
0A
F103
01
F104
01
F105
0C

.

.

.

.

.

.

 

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, F1
 
LXI H,F100
Point to get count of numbers
F003
AF
 
XRA A
Clear accumulator
F004
4E
 
MOV C,M
Load count from memory to C
F005
23
 
INX H
Point to next location
F006
46
LOOP
MOV B,M
Load memory to B
F007
A8
 
XRA B
XOR B with Accumulator
F008
23
 
INX H
Point to next location
F009
0D
 
DCR C
Decrease C by 1
F00A
C2, 06, F0
 
JNZ LOOP
Jump to LOOP until Z = 1
F00D
32, 50, F1
 
STA F150
Store number at F150
F010
76
 
HLT
Terminate the program

 

Output

Address
Data

.

.

.

.

.

.

F150
0A

.

.

.

.

.

.

 

 

 

 

 

 

 

 

 

Updated on: 30-Jul-2019

314 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements