8085 program for Linear search | Set 2
Problem – Write an assembly language program in 8085 microprocessor to find a given number in the list of 10 numbers, if found store 1 in output else store 0 in output.
Example –

Assumption – Data to be found at 2040H, list of numbers from 2050H to 2059H and output at 2060H.
Algorithm –
- Load data byte to be searched in B register and counter in D register.
- Load starting element in Accumulator.
- Compare Accumulator and B register.
- If zero flag is set then JUMP to point 8 (as CMP instruction sets Zero flag when both are equal).
- Decrement D register
- If D>0 take next element in Accumulator and go to point 3.
- If D=0, this means element not found then store 00H. End the program.
- Store 01H as element found. End the program.
Program –
| Address | Label | Instruction | Comment |
|---|---|---|---|
| 2000H | Data | LXI H, 2040H | Load address of data to be searched |
| 2003H | MOV B, M | Store data to be searched in B register | |
| 2004H | LXI H, 2050H | Load starting address of list | |
| 2007H | MVI D, 0AH | Counter for 10 elements | |
| 2009H | NEXT | MOV A, M | Retrieve list element in Accumulator |
| 200AH | CMP B | Compare element with data byte | |
| 200BH | JZ STOP | Jump if data byte found | |
| 200EH | INX H | Next element of list | |
| 200FH | DCR D | Decrement counter | |
| 2010H | JNZ NEXT | Jump to NEXT if D>0 | |
| 2013H | LXI H, 2060H | Load address of output | |
| 2016H | MVI M, 00H | Store 00H | |
| 2018H | HLT | Halt | |
| 2019H | STOP | LXI H, 2060H | Load address of output |
| 201CH | MVI M, 01H | Store 01H | |
| 201EH | HLT | Halt |
Explanation –
- One by one all elements are compared with data byte in B register
- If element found, loop ends and 01H is stored
- Loop executes 10 number of times
- If at the end of 10 iterations, data byte is not found then 00H is stored
Refer for Set-1: 8085 program to search a number in an array of n numbers
Recommended Posts:
- 8085 program for Binary search
- 8085 program to search a number in an array of n numbers
- 8085 program to add 2-BCD numbers
- 8085 program to add two 16 bit numbers
- 8085 program to add two 8 bit numbers
- 8085 program to sum of two 8 bit numbers without carry
- 8085 program to multiply two 8 bit numbers
- 8085 program for bubble sort
- 8085 program to check whether the given number is even or odd
- 8085 program to swap two 8-bit numbers
- 8085 program to multiply two 16-bit numbers
- 8085 program to reverse 16 bit number
- 8085 program to add numbers in an array
- 8085 program to find the sum of a series
- 8085 program to divide two 16 bit numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



