So far in this 8085 programming series, we have only done calculation related to 8-bit hexadecimal and decimal numbers.
But in this post, we are going to learn how we can add two 16-bit hexadecimal numbers. Even though we cannot execute 32-bit number operations but we can perform the 16-bit operation.
For this 8085 program, we are going to use the concept of MSB (Most Significant Bit) and LSB (Least Significant Bit). As we are going to perform addition operation between two 16-bit hexadecimal numbers, we are going to use 4 memory location to store the LSB and MSB, two more memory location to store the result, and an additional one to store the carry.
For addition take small numbers that won’t produce carry, because if it does then we have to manage it. Don’t worry we are going to use a program that’s gonna handle the carry but if you want to make your programs shorter than it’s better to take small numbers.
Let the first 16-bit number be 34ACH, the ACH number will be stored at 2000H and the rest part i.e. 34H will be stored at memory location 2001H.
In a similar way, we are going to store the next 16-bit hexadecimal number 1E9BH in memory location 2002H and 2003H. We are also going to leave memory location 2005H, 2006H and 2007H to store the result and the carry.
LHLD 2000 // we are going to store the content of 200H and 2001H ML in HL
XCHG // using exchange instruction, we are going to copy the content to DE register pair
LHLD 2002 //again we are going to use LHLD instruction to copy the content of 2002H and 2003H ML to HL register pair
MVI C,00 //to adjust the carry we are going to take C register and make its content NULL
DAD D // using DAD instruction we are going to perform the addition instruction
JNC Label // JNC is used as a jump instruction, it will work only when no carry is generated
INR C //in case a carry is generated, we are going to increment the value of C register to 1
Label SHLD 2004 // using SHLD instruction, we will store the result in 2004H and 2005H memory location
MOV A, C //now to adjust the carry we copy the content of C reg in the accumulator
STA 2006//Lastly, using STA we store the content of accumulator in 2006H memory location
|Memory Location||OPCODE||Operand||Label||Hex Code|