In this program, we will write an 8085 program to pack the two unpacked BCD numbers in the 8085 microprocessor with a program flow chart and explanation of the program.
8085 program to pack the two unpacked BCD numbers
Program Statement
Write a program to pack the two unpacked BCD numbers. Assume the two unpacked digits are available at memory locations D000H and D001H. Assume that the least significant digit is stored a D000H. Store the result in memory location D002H.
Explanation of Program
- We have two digits at memory locations D000H and D001H in unpacked BCD form. The LCB is stored at D000H and MSB is stored at D001H.
- We need to pack the two BCD numbers. i.e. we need to combine the two numbers.
- To make the digit at D001h as MSB, we will rotate it 4 times to left using RLC instruction. After rotating the digit by 4 times if the digit = 09H, then it will become 90H.
- Then we will add the two numbers. The result is packed with BCD numbers. Store the result in memory location D002H.
e.g. D001H = 02H, D001H = 09H then the result will be D002H = 92H (result)
Assembly Language Program
Instruction | Comments | Operation |
---|---|---|
LDA D001 H | Load the MSB digit in the accumulator | A = 09H A = 0000 1001 |
RLC | Rotate the number to the left by 1. | A = 12H A = 0001 0010 |
RLC | Rotate the number to the left by 1. | A = 24H A = 0010 0100 |
RLC | Rotate the number to the left by 1. | A = 48H A = 0100 1000 |
RLC | Rotate the number to the left by 1. | A = 90H A = 1001 0000, CY = 0 |
ANI F0H | Make the LSB digit zero. | A = 90H |
MOV B, A | Store the partial result. | B = 90H |
LDA D000H | Load the LSB BCD digit in the accumulator. | A = 02H |
ADD B | Add the lower BCD digit to the upper BCD digit. | A = 90H + 02H A = 92H |
STA D002H | Store the result. | D002H = 92H |
HLT | Termiate program executaion. | Stop |