Ex. No.
1 Addition of two 8 bit numbers
AIM: To write a program to add two 8 bit numbers using 8051 microcontroller.
APPARATUS REQUIRED: 8051 microcontroller kit, Power supply.
ALGORITHM:
1. Clear the carry flag.
2. Store the address of the first input (Data 1) in DPTR register.
3. Move Data 1 pointed by DPTR to Accumulator.
4. Move that value to register R0.
5. Increment DPTR so that it has the address of the second input (Data 2).
6. Move the Data 2 pointed by DPTR to Accumulator.
7. Add accumulator and R0.
8. Increment DPTR so that it has the address of the result (lower order
byte).
9. Move the accumulator contents to address pointed by DPTR.
10.Increment DPTR so that it has the address of the result (higher order
byte).
11.Clear the accumulator.
12.Copy the Carry flag value to Accumulator’s least significant bit.
13.Move the accumulator contents to address pointed by DPTR.
14.Stop the program.
PROCEDURE:
To type the program:
Reset (RST) Start address 4100 ADS Type opcode
To enter input:
Reset (RST) Address 4150 Input Data
To execute the program:
Reset (RST) Start address 4100 EXE
To check the output:
Reset (RST) Result address 4152 ADS
PROGRAM:
PROGRAM for ADDITION
LABEL MNEMONICS MEMORY OPCODE
LOCATION
CLR C 4100 C3
MOV DPTR, #4150H 4101 90, 41, 50
MOVX A,@DPTR 4104 E0
MOV R0,A 4105 F8
INC DPTR 4106 A3
MOVX A,@DPTR 4107 E0
ADD A,R0 4108 28
INC DPTR 4109 A3
MOVX @DPTR,A 410A F0
INC DPTR 410B A3
CLR A 410C E4
MOV ACC.0,C 410D 92
MOVX @DPTR,A 410E F0
HERE: SJMP HERE 410F 80, 41, 0F
RESULT: Thus the program for addition of two 8 bit numbers was executed
and results were verified using 8051 microcontroller kit.
MANUAL CALCULATION:
Case 1:
DATA 1 32 H
DATA 2 27 H
-----------------------
SUM 59 H
-----------------------
INPUT
MEMORY LOCATION DATA
Data 1 4150 32
Data 2 4151 27
OUTPUT
MEMORY LOCATION DATA
Sum 4152 59
Carry 4153 00
MANUAL CALCULATION:
Case 2:
DATA 1 FF H 255 + 255 = 510 1FE in hex
DATA 2 FF H
-----------------------
SUM 1FE H
-----------------------
INPUT
MEMORY LOCATION DATA
Data 1 4150 FF
Data 2 4151 FF
OUTPUT
MEMORY LOCATION DATA
Sum 4152 FE
Carry 4153 01