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 –
- Load two numbers from memory 2050 & 2051 to register L and H .
- Move one number(H) to Accumulator A and subtract other number(L) from it.
- 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 –
- LHLD 2050: load data from memory 2050 & 2051 to register L and H.
- MOV A, H: transfer contents of register H to A.
- SUB L: subtract contents of register L from A and store it to A.
- JP 200D: jump to address 200D if result is positive.
- MOV A, L: transfer contents of register L to A.
- STA 3050: store data of A to memory address 3050.
- HLT:: END.
- MOV A, H: transfer contents of register H to A.
- STA 3050: store data of A to memory address 3050.
- HLT: END.