In the last program, we saw how we can evaluate an expression which included 16-bit hexadecimal numbers, however, in the last two programs, we only did addition operation.
But in this program other than addition, we are also going to perform a subtraction operation.
Anyways, like the previous program, we are going to use any specific kind of addressing mode for this program.
For this program also we are going to need in total seven memory locations. Starting from the 2000H memory location, we are going to store the first 16-bit hexadecimal number; AC82H.
And then in the 2002H and 2003H memory location, we are going to store the second 16-bit hexadecimal number i.e. 123BH, and in finally in the 2004H memory location, we are going to store the 8-bit hexadecimal number 24H.
Now, in order to store the result, we can use 2005H and 2006H memory location.
LHLD 2000H //the content of 2000H and 2001H memory location will be copied to HL register pair
XCHG //using XCHG instruction we are going to copy the content of HL register pair to DE pair
LHLD 2002H //now we load the content of 2002H into HL register pair
DAD D// now using DAD instruction we are going to add the content of HL register pair and DE register pair
MOV A, L //after performing addition operation you’ll need to copy the LSB to accumulator
MOV D, H //and then we’ll copy the MSB in D or any other general purpose register
LXI H, 2004H //using LXI we’ll point HL register to 2004H memory location
SUB M // and then we will perform the subtraction operation of the LSB with the 8-bit hexadecimal number
STA 2005H //next, using STA we’ll copy the content of accumulator in 2005H memory location
MOV A, D // now we’ll move the MSB to accumulator so that we could store it in a memory location
STA 2006H //finally we’ll store the MSB in 2006H memory location
|Memory Location||OPCODE||Operand||Label||Hex Code|