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



Programming Details
Memory Location OPCODE Operand Label Hex Code
2003 LXI H, 2000 21H
2004 00H
2005 20H
2006 MOV A,M 7EH
2007 CMA 2FH
2008 ADI 01 C6H
2009 01H
200A MOV B,A 47H
200B INX H 27H
200C MOV A, M 7EH
200D ADD B 80H
200E STA 2003 32H
200F 20H
2010 03H
2011 HLT 76H