Related Articles
8086 program to add two 16 bit BCD numbers with carry
• Last Updated : 18 May, 2018

Problem – Write an assembly language program to add two 16 bit BCD numbers with carry in 8086 microprocessor.

Example –

Algorithm –

1. Load the lower part of both the 16 bit BCD numbers in different locations.
2. Add each number by adding first its lower part.
3. Repeat the above step also by adding the carry if any.
4. Make the lower part of register 00 and add the carry. This is done to obtain the carry.
5. Display all the mumbers with highest part as carry, middle part as addition of the higher BCD 8 bits and lower part as the lower BCD 8 bits.

Program –

Memory Address Mnemonics Comments
0400 MOV AL, [500] AL ← [500]
0404 MOV BL, [502] BL ← [502]
0408 ADD AL, BL AL ← AL+BL
040A DAA Decimal Adjust AL
040B MOV [600], AL AL → [600]
040F MOV AL, [501[ AL ← [501]
0413 MOV BL, 503 BL ← [503]
0417 ADC AL, BL AL ← AL+BL+CY
0419 DAA Decimal Adjust AL
041A MOV [601], AL AL → [601]
041E MOV AL, 00 AL ← 00H
0420 ADC AL, AL AL ← AL+AL+CY
0422 MOV [602], AL AL → [602]
0426 HLT Stop Execution

Explanation –

1. MOV AL, [500] moves the value stored at memory location 500 to AL register.
2. MOV BL, [502] moves the value stored at memory location 500 to BL register.
3. ADD AL, BL add the values in AL and BL registers.
4. DAA adds 6 to the digit which is greater than 9.
5. MOV [600], AL display the added value to memory location 600.
6. MOV AL, [501] moves the value stored at memory location 501 to AL register.
7. MOV BL, [503] moves the value stored at memory location 503 to BL register.
8. ADC AL, BL add the values in AL and BL registers and carry (if any).
9. MOV BL, [503] moves the value stored at memory location 503 to BL register.
10. MOV [601], ALdisplay the added value to memory location 601.
11. MOV AL, 00 moves 00 in AL register.
12. ADC AL, AL add the values in AL and AL registers and carry (if any).
13. MOV [602], AL display the added value to memory location 602.
14. HLT stops execution.

Next related article – 8086 program to add two 8 bit BCD numbers

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :