In this program, we are going to write an assembly language program to add two 16-bit numbers in 8085 microprocessor with a program flow chart and explanation of the program.
Add two 16-bit numbers in 8085
Program Statement
Write a program to add the 16-bit number in memory locations D000H and D001H with the 16-bit number in memory locations D002H and D003H. The most significant 8 bits of the two numbers to be added are in memory locations D001H and D003H. Store the result in memory locations D004H and D005H with the most significant byte in memory location D005H
Explanation of Program
- We have two 16-bit numbers. Let the two numbers be 1234H and 4321H.
- We have to add the word at memory locations D000H and D001H with the word at memory locations D002H and D003H.
- For computing the addition there are two methods.
- In the first method, we will add the two LSBs and the two MSBs separately and store the result.
- In the second method, we will store the two numbers in the register pairs DE and HL. Then using the DAD instruction we will add the two 16-bit numbers. The result of the addition will be stored in the HL register pair.
- D000H = 34H, D001H = 12H, D002H = 21H, D003H = 43H
- Result = 1234 H + 4321 H = 5555 H
- D004H = 55H and D005H = 55H
Method 1
- In the first method, we will add the two LSBs and the two MSBs separately and store the result.
Assembly Language Program
Instruction | Comment | Operation |
---|---|---|
LHLD D000H | Load the first 16-bit numbers in the HL register pair. | H = 12H, L = 34H |
XCHG | save the 16-bit number in the DE register pair. | D = 12H, E = 34H |
LHLD D002H | Load the second 16-bit numbers in the HL register pair. | H = 43H, L = 21H |
MOV A, E | Load the lower byte of the first number in the accumulator | A = 34H |
ADD L | Add the two lower bytes | A = A + L = 34 + 21 A = 55H |
MOV L, A | Store the result in the L register | L = 55H |
MOV A, D | Load the higher byte of the first number in the accumulator | A = 12H |
ADC H | Add the two higher bytes along with the carry of the lower byte addition. | A= A + H + CY A = 12 + 43 + 0 A = 55H |
MOV H, A | Store the result in the H register | H = 55H |
SHLD D004H | Store the 16-bit result in memory locations D004H and D005H. | D004H = 55H D005H = 55H |
HLT | Terminate program execution | Stop |
Flow Chart of Program
Method 2
- In the second method, we will store the two numbers in the register pairs DE and HL. Then using the DAD instruction we will add the two 16-bit numbers. The result of the addition will be stored in the HL register pair.
Assembly Language Program
Instruction | Comment | Operation |
---|---|---|
LHLD D000H | Load the first 16-bit number | H = 12H, L = 34H |
XCHG | Save the first 16-bit number in the DE register pair. | D = 12H, E = 34H |
LHLD D002H | Load the second 16-bit number | H = 43H, L = 21H |
DAD D | add the two 16-bit numbers. | HL = HL + DE HL = 4321 + 1234 HL = 5555H H = 55H, L = 55H |
SHLD D004H | Store the 16-bit result. | D004H= 55H D005H = 55H |
HLT | Terminate program execution | Stop |