On this page
16-bit Addition
This program demonstrates how to add two 16-bit numbers on the 8051 microcontroller.
Description
The program adds two 16-bit numbers:
- Num1:
0A B2H - Num2:
12 34H
The result is stored in registers R7 (higher byte) and R6 (lower byte).
Code
| |
Explanation
- MOV A, #0B2H: Load the lower byte of Num1 into accumulator
- ADD A, #034H: Add the lower byte of Num2
- MOV R6, A: Store the lower byte result in R6
- MOV A, #0AH: Load the higher byte of Num1 into accumulator
- ADDC A, #12H: Add the higher byte of Num2 with carry
- MOV R7, A: Store the higher byte result in R7
The ADDC instruction is used for the higher byte to include any carry from the lower byte addition.