In this program, we are going to write an assembly language program to subtract two 16-bit numbers in 8085 microprocessor with a program flow chart and explanation of the program.
Subtract two 16-bit numbers in 8085
Program Statement
Subtract the 16-bit number in memory locations D002H and D003H from the 16-bit number in memory locations D000H and D001H. The most significant 8 bits of the two numbers 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, we have to subtract the word at memory locations D002H and D003H from the word at memory locations D000H and D001H.
- We will subtract the two LSBs and MSBs separately and store the result.
- E.g. D000H = 31H, D001H = 12H, D002H = 00H, D003H = 01H
- Result: 1234H – 0100H = 1134H
- D004H = 34H, D005H = 11H
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 first 16-bit number in the DE register pair. | D = 12H, E = 34H |
LHLD D002H | Load the second 16-bit number in the HL register pair. | H = 01H, H = 00H |
MOV A, E | Load the lower byte of the first number in the accumulator | A = 34H |
SUB L | Subtract the lower byte of the second number | A = A – L A = 34 – 00 A = 34H, CY = 0 |
MOV L, A | Store the result in register L. | L = 34H |
MOV A, D | Load the higher byte of the first number in the accumulator | A = 12H |
SBB H | Subtract the higher byte of the second number with a borrow of the previous subtraction. | A = A – H – CY A = 12 – 01 – 0 A = 11H |
MOV H, A | Store the result in register H. | H = 11H |
SHLD D004H | Store the 16-bit result in memory locations D004H and D005H | D004H = 34H D005H = 11H |
HLT | Terminate program execution | Stop |