Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

8085 program for Linear search | Set 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 –

  1. Load data byte to be searched in B register and counter in D register.
  2. Load starting element in Accumulator.
  3. Compare Accumulator and B register.
  4. If zero flag is set then JUMP to point 8 (as CMP instruction sets Zero flag when both are equal).
  5. Decrement D register
  6. If D>0 take next element in Accumulator and go to point 3.
  7. If D=0, this means element not found then store 00H. End the program.
  8. Store 01H as element found. End the program.

Program –

AddressLabelInstructionComment
2000HDataLXI H, 2040HLoad address of data to be searched
2003HMOV B, MStore data to be searched in B register
2004HLXI H, 2050HLoad starting address of list
2007HMVI D, 0AHCounter for 10 elements
2009HNEXTMOV A, MRetrieve list element in Accumulator
200AHCMP BCompare element with data byte
200BHJZ STOPJump if data byte found
200EHINX HNext element of list
200FHDCR DDecrement counter
2010HJNZ NEXTJump to NEXT if D>0
2013HLXI H, 2060HLoad address of output
2016HMVI M, 00HStore 00H
2018HHLTHalt
2019HSTOPLXI H, 2060HLoad address of output
201CHMVI M, 01HStore 01H
201EHHLTHalt

Explanation –

  1. One by one all elements are compared with data byte in B register
  2. If element found, loop ends and 01H is stored
  3. Loop executes 10 number of times
  4. 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

My Personal Notes arrow_drop_up
Last Updated : 05 Sep, 2018
Like Article
Save Article
Similar Reads