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.
Assumption – Data to be found at 2040H, list of numbers from 2050H to 2059H and output at 2060H.
- 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.
|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|
|2019H||STOP||LXI H, 2060H||Load address of output|
|201CH||MVI M, 01H||Store 01H|
- 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
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.
- 8085 program to search a number in an array of n numbers
- 8085 program for Binary search
- Difference between Linear Pipeline and Non-Linear Pipeline
- 8085 program to find the set bit of accumulator
- 8085 program to convert a BCD number to binary
- 8085 program to find the element that appears once
- 8085 program to find maximum and minimum of 10 numbers
- 8085 program to find maximum of two 8 bit numbers
- 8085 program to add two 8 bit numbers
- 8085 program to multiply two 8 bit numbers
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to find the factorial of a number
- 8085 program to count the number of ones in contents of register B
- 8085 program to add two 16 bit numbers
- 8085 program to exchange a block of bytes in memory
- 8085 program to find square root of a number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to convert 8 bit BCD number into ASCII Code
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to swap two 8-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 firstname.lastname@example.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.