8085 program to find larger of two 8 bit numbers

Problem – Write a program in 8085 microprocessor to find out larger of two 8-bit numbers, where numbers are stored in memory address 2050 and 2051, and store the result into memory address 3050.

Example –

Algorithm –

  1. Load two numbers from memory 2050 & 2051 to register L and H .
  2. Move one number(H) to Accumulator A and subtract other number(L) from it.
  3. if result is positive then move the number(H) to A and store value of A at memory address 3050 and stop else move the number(L) to A and store value of A at memory address 3050 and stop.

Program –

MEMORY ADDRESS MNEMONICS COMMENT
2000 LHLD 2050 H<-(data at 2051)&L<-(data at 2050)
2003 MOV A, H A<-H
2004 SUB L A<-A-L
2005 JP 200D JUMP TO 200D IF NO. IS POSITIVE
2008 MOV A, L A<-L
2009 STA 3050 A->(in memory 3050)
200C HLT STOP
200D MOV A, H A<-H
200E STA 3050 A->(in memory 3050)
2011 HLT STOP

Explanation –

  1. LHLD 2050: load data from memory 2050 & 2051 to register L and H.
  2. MOV A, H: transfer contents of register H to A.
  3. SUB L: subtract contents of register L from A and store it to A.
  4. JP 200D: jump to address 200D if result is positive.
  5. MOV A, L: transfer contents of register L to A.
  6. STA 3050: store data of A to memory address 3050.
  7. HLT:: END.
  8. MOV A, H: transfer contents of register H to A.
  9. STA 3050: store data of A to memory address 3050.
  10. HLT: END.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.