Problem – Write an assembly language program to add two 16 bit BCD numbers with carry in 8086 microprocessor.
Example –
Algorithm –
- Load the lower part of both the 16 bit BCD numbers in different locations.
- Add each number by adding first its lower part.
- Repeat the above step also by adding the carry if any.
- Make the lower part of register 00 and add the carry. This is done to obtain the carry.
- Display all the numbers 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 –
- MOV AL, [500] moves the value stored at memory location 500 to AL register.
- MOV BL, [502] moves the value stored at memory location 500 to BL register.
- ADD AL, BL add the values in AL and BL registers.
- DAA adds 6 to the digit which is greater than 9.
- MOV [600], AL display the added value to memory location 600.
- MOV AL, [501] moves the value stored at memory location 501 to AL register.
- MOV BL, [503] moves the value stored at memory location 503 to BL register.
- ADC AL, BL add the values in AL and BL registers and carry (if any).
- MOV BL, [503] moves the value stored at memory location 503 to BL register.
- MOV [601], AL display the added value to memory location 601.
- MOV AL, 00 moves 00 in AL register.
- ADC AL, AL add the values in AL and AL registers and carry (if any).
- MOV [602], AL display the added value to memory location 602.
- HLT stops execution.
Next related article – 8086 program to add two 8 bit BCD numbers