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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
;Num1: 0A B2
;Num2: 12 34

ORG 0000H
	MOV A , #0B2H
	ADD A , #034H
	MOV R6 , A
	MOV A , #0AH
	ADDC A , #12H
	MOV R7 , A
END

Explanation

  1. MOV A, #0B2H: Load the lower byte of Num1 into accumulator
  2. ADD A, #034H: Add the lower byte of Num2
  3. MOV R6, A: Store the lower byte result in R6
  4. MOV A, #0AH: Load the higher byte of Num1 into accumulator
  5. ADDC A, #12H: Add the higher byte of Num2 with carry
  6. 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.