In this program, we are going to write an assembly language program to subtract two 8-bit numbers in the 8085 microprocessor with a program flow chart and explanation of the program.
Subtract two 8-bit numbers in 8085
Subtract the content of memory location D001H from memory location D000H and place the result in memory location D002H.
Explanation of Program
- We have two numbers at memory locations D000H and D001H. Let these numbers be 50H and 20H. We have to subtract these numbers.
- using the SUB instruction, we will subtract the two numbers.
- Store the result at the memory location D002H.
- E.g. : D000H = 50 H and D001H = 20 H
- Result: D002H = 50H – 20H = 30H
Assembly Language Program
|LXI H, D000H||set HL as memory pointer at memory location D000H||H=D0H, L=00H|
|MOV A, M||Load the first operand in the accumulator||A=50H|
|INX H||Increment HL to point to the next memory location i.e. D001H||H=D0H, L=01H|
D001H : 20H
|SUB M||Increment HL to point to the next memory location i.e. D002H||A= A-M|
|INX H||Increment HL to point to next memory location i.e. D002H||H=D0H, L=02H|
|MOV M, A||Store the result||D002H= 30H result|
|HLT||terminate program execution||Stop|