Write an 8085 program to find 2’s complement of a given 16-bit hexadecimal number - ChromeTechny
Home » Write an 8085 program to find 2’s complement of a given 16-bit hexadecimal number
8085 Programming

Write an 8085 program to find 2’s complement of a given 16-bit hexadecimal number

In the last program, we show how we can perform 2’s complement operation of an 8-bit decimal number, moving on, in this program, we are going to learn how we can perform 2’s complement operation on a 16-bit hexadecimal number.

Now when it comes to addressing mode, like the last program in this program also, we are going to specifically be using direct addressing mode.

Input:

Let the 16-bit hexadecimal number be 0512H, which we will be storing at 2000H and 2001H memory location using the concept of LSB and MSB, and the end result will be stored at 2002H and 2003H memory locations.

Instruction:

LHLD 2000H// using LDA we copy the content of 2000H memory location into the HL register pair

MOV A,L // using MOV instruction, we’ll copy the LSB in the accumulator

CMA // using CMA instruction we will perform the 1’s complement operation

MOV L,A// once we perform the 1’s complement operation, we’ll copy the LSB back to L register

MOV A,H // next, we’ll copy the MSB into the accumulator

CMA // using CMA instruction we perform the 1’s complement operation

MOV H,A // once we  perform the 1’s complement operation we’ll copy the MSB back to the H register

INX H// using INX instruction we’ll increment the content of HL register pair by one

SHLD 2002H //finally we store the result in 2002H and 2003H memory location

HLT

Programming Details
Memory Location OPCODE Operand Label Hex Code
2004 LHLD 2000H 2AH
2005 00H
2006 20H
2007 MOV A,L 7DH
2008 CMA 2FH
2009 MOV L,A 6FH
200A MOV A,H 7CH
200B CMA 2FH
200C MOV H,A 67H
200D INX H 23H
200E SHLD 2002H 22H
200F 02H
2010 20H
2011 HLT 76H

About the author

Ayan