8085 Program to Search a Number in an Array



In this program we will see how to search an element in an array of bytes using 8085.

Problem Statement

Write 8085 Assembly language program to search a key value in an array of data using linear search technique.

Discussion

In this program 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. After executing this program, it will return the address of the data where the item is found and store the address at location 9000H and9001H. If the item is not found, it will return FFFFH.

If 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 atFFFFH, 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

Address HEX 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 by1
F00D C2, 07, F0
JNZ LOOP     When Count is not 0, jump to LOOP
F010 21, FF, FF
LXI H, FFFF Load FFFFHinto HL pair
F013 22, 00, 90
SHLD 9000H   Store at9000H
F016 C3, 1C, F0
JMP DONE    Jump to DONE
F019 22, 00, 90 FOUND SHLD 9000H   Store at9000H
F01C 76 DONE HLT Terminate the program


Output

Address Data
... ...
9000 06
9001 80
... ...
Updated on: 2019-07-30T22:30:24+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements