Addition of two 16-bit numbers: 8085 programming
In this post, we will write programs in 8085 Assembly language for the addition of two 16-bit numbers.
In program 1, eight bit addition instructions are used (ADD and ADC) and addition is performed in two steps. First lower byte addition using ADD instruction and then higher byte addition using ADC instruction.
In program 2, 16-bit addition instruction (DAD) is used.
Addition of two 16-bit numbers: 8085 programming
Problem statement 1: Add two 16-bit numbers (using ADD and ADC instructions)
8085 Assembly language program code (with ADD and ADC instructions)
Memory Address(H) | Machine Code(H) | Label | Mnemonics(Instruction) | Comments |
C000 C001 C002 | 2A 00 C1 | LHLD C100H | Get first I6 bit number in HL | |
C003 | EB | XCHG | Save first I6 bit number in DE | |
C004 C005 C006 | 2A 02 C1 | LHLD C102H | Get second I6 bit number in HL | |
C007 | 7B | MOV A, E | Get lower byte of the first number | |
C008 | 85 | ADD L | Add lower byte of the second number | |
C009 | 6F | MOV L, A | Store result in L register | |
C00A | 7A | MOV A, D | Get higher byte of the first number | |
C00B | 8C | ADC H | Add higher byte of the second number with CARRY | |
C00C | 67 | MOV H, A | Store result in H register | |
C00D C00E C00F | 22 04 C1 | SHLD C104H | Store I6bit result in memory locations C104H and C105H. | |
C010 | 76 | HLT | Terminate program execution |
Input Data
Memory Address(H) | Data(H) |
C100 | 15 |
C101 | 1C |
C102 | B7 |
C103 | 5A |
Result
1C15 + 5AB7H = 76CCH
Memory Address(H) | Data(H) |
C104 | CC |
C105 | 76 |
Problem statement 2: Add two 16-bit numbers using DAD instruction.
8085 Assembly language program code (with DAD instruction)
Memory Address(H) | Machine Code(H) | Label | Mnemonics(Instruction) | Comments |
C000 C001 C002 | 2A 00 C1 | LHLD C100H | Get first I6 bit number | |
C003 | EB | XCHG | Save first I6 bit number in DE | |
C004 C005 C006 | 2A 02 C1 | LHLD C102H | Get second I6 bit number in HL | |
C007 | 19 | DAD D | Add DE and HL | |
C008 C009 C00A | 22 04 C1 | SHLD C104H | Store I6 bit result in memory locations C104H and C105H. | |
C00B | 76 | HLT | Terminate program execution |
Input Data
Memory Address(H) | Data(H) |
C100 | 15 |
C101 | 1C |
C102 | B7 |
C103 | 5A |
Result
1C15 + 5AB7H = 76CCH
Memory Address(H) | Data(H) |
C104 | CC |
C105 | 76 |