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 –
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

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

