Write an 8085 program to add two 16-bit decimal numbers - ChromeTechny
Home » Write an 8085 program to add two 16-bit decimal numbers

Write an 8085 program to add two 16-bit decimal numbers

 In the last program, we discussed on how you can add two 16-bit hexadecimal numbers, but in this program, we are going to add two 16-bit decimal numbers.

Like the last program, in this program also we are going to use the concept the MSB and LSB. As we are going to perform the addition operation, we are going to use 4 successive memory locations to store the numbers, and two more locations to store the result, and one more additional ML to store the carry in case, a carry gets generated.

However, it’s better to avoid the carry or use small numbers to add so that no carry gets generated.

Input:

Let the first 16-bit decimal number be 1582D, the 82D will be stored at 2000H ML, and 15D will be stored at 2001H ML.

And the second 16-bit decimal number be 1431D, the LSB i.e. 31D will be stored at 2002H ML, and the MSB i.e. 14D will be stored at 2003H ML.

Furthermore, we are going to reserve 3 more memory locations 2004H, 2005H and 2006H to store the result and carry.

Program:

LXI H, 2000H

MVI B,00

MOV A,M

INX H

ADD M

DAA

JNC label

INR B

Label STA 2004

MOV A, B

INX H

ADD M

DAA

STA 2006

HLT

 

Programming Details
Memory Location OPCODE Operand Label Hex Code
2007 LXI H, 2000H 21H
2008 00H
2009 20H
200A MVI B, 00 06H
200B 00H
200C MOV A,M 7EH
200D INX H 23H
200E ADD M 86
200F DAA 27H
2010 JNC label D2H
2011 14H
2012 20H
2013 INR B 04H
2014 STA 2004 label 32H
2015 04H
2016 20H
2017 MOV A,B 78H
2018 INX H 23H
2019 ADD M 86H
201A INX H 23H
201B ADD M 86H
201C DAA 27H
201D STA 2006H 32H
201E 06H
201F 20H
2020 HLT 76H

About the author

Ayan

Add Comment

Click here to post a comment

Your email address will not be published. Required fields are marked *