Write a 8085 program to subtract two 8-bit hexadecimal numbers using 2’s complement
Doing 8-bit hexadecimal addition is quite easy but doing 8-bit subtraction is kind of complicated.
Anyway, in this program, we are going to learn how we can perform subtraction operation of two 8-bit hexadecimal numbers using 2’s complement.
For this program, we are going to need three consecutive memory locations; 2000H to 2002H. In the first two memory locations we are going to store the 8-bit hexadecimal numbers; CAH and 1BH.
And in the 2002H memory location, we are going to store the result.
LXI H, 2000H// using LXI the HL register pair will now point to the content of 2000H ML
MOV A, M // the content of 2000H will be moved to the accumulator
CMA // using CMA, 1’s complement operation is performed
ADI 01 // using ADI 01H is added with the content of accumulator
MOV B, A // the content of accumulator is copied to B register
INX H // HL register pair get incremented by 1
MOV A, M// the content of 2001H memory location is moved to the accumulator
ADD B // addition operation is performed between the content of accumulator and the content of B register
STA 2002// the result stored in the accumulator is copied to 2002H ML using STA
|Memory Location||OPCODE||Operand||Label||Hex Code|