8085 program to search a number in an array of n numbers


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

AddressData
......
800006
800155
800211
800322
800433
800544
800655
800766
......


Flow Diagram

Program

AddressHEX CodesLabelsMnemonicsComments
F00021, 00, 80
LXI H,8000HPoint to get array size
F0034E
MOV C, MGet the size of array
F00423
INX H   Point to next location
F00546
MOV B, MGet the key value to search
F00678
MOV A, BTake the key into acc
F00723LOOPINX H   Point to next location
F008BE
CMP M   Compare memory element with Acc
F009CA, 19, F0
JZ FOUND    When Z flag is set, go to FOUND
F00C0D
DCR C   Decrease C by1
F00DC2, 07, F0
JNZ LOOP    When Count is not 0, jump to LOOP
F01021, FF, FF
LXI H, FFFFLoad FFFFHinto HL pair
F01322, 00, 90
SHLD 9000H  Store at9000H
F016C3, 1C, F0
JMP DONE   Jump to DONE
F01922, 00, 90FOUNDSHLD 9000H  Store at9000H
F01C76DONEHLTTerminate the program


Output

AddressData
......
900006
900180
......

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements