Program to perform linear search in 8085 Microprocessor


Here we will see how to perform the linear search in 8085 microprocessor. The linear search is searching elements sequentially from start to end position.

Problem Statement 

Write an 8085 Assembly language program to search a key value in a block of data using linear search (sequential search) technique.

Discussion

Suppose the data are stored at location 8002H to 8007H. The 8000H is containing the size of the block, and 8001H is holding the key value to search. When we execute the program, it will return the address of the data where the item is found and store the address at location 9000H and 9001H. If the item is not found, it will return FFFFH.

f the data is present in the memory at FFFFH, then also it will store FFFFH, so it is ambiguous condition. We are assuming that the data are not stored at FFFFH, so we have chosen that value to indicate the data is not present.

Input

Address
Data


8000
06
8001
55
8002
11
8003
22
8004
33
8005
44
8006
55
8007
66


 

Flow Diagram−

Program

AddressHEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80
 
LXI H,8000H
Point to get array size
F003
4E
 
MOV C,M
Get the size of array
F004
23
 
INX H  
Point to next location
F005
46
 
MOV B,M
Get the key value to search
F006
78
 
MOV A,B
Take the key into acc
F007
23
LOOP
INX H  
Point to next location
F008
BE
 
CMP M  
Compare memory element with Acc
F009
CA, 19, F0
 
JZ FOUND  
When Z flag is set, go to FOUND
F00C
0D
 
DCR C  
Decrease C by 1
F00D
C2, 07, F0
 
JNZ LOOP  
When Count is not 0, jump to LOOP
F010
21, FF, FF
 
LXI H, FFFF
Load FFFFH into HL pair
F013
22, 00, 90
 
SHLD 9000H
Store at 9000H
F016
C3, 1C, F0
 
JMP DONE  
Jump to DONE
F019
22, 00, 90
FOUND
SHLD 9000H
Store at 9000H
F01C
76
DONE
HLT
Terminate the program

 

Output

Address
Data


9000
06
9001
80


 

 

Updated on: 05-Oct-2019

457 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements