8: Addition, Subtraction, Multiplication and Division using 8051
8.1 Introduction:
The purpose of this experiment is to add, subtract, multiply and divide the given two 8
bit numbers and store them in a memory location. The student should also be able to design the
addition and subtraction with carry and borrow.
8.2 Hardware Requirement:
The 8051 Microcontroller kit , Power supply.
8.3 Program Logic:
To perform addition in 8051 one of the data should be in accumulator, another data can
be in any of the general purpose register or in memory or immediate data. After addition the
sum will be in accumulator. The sum of two 8-bit data can be either 8-bits(sum only) or 9-
bits(sum and carry). The accumulator can accumulate only the sum and there is a carry the
8051 will indicate by setting carry flag. Hence one of the register is used to account for carry.
The 8051 has MUL instruction unlike many other 8-bit processors. MUL instruction
multiplies the unsigned 8-bit integers in A and B. The lower order byte of the product is left in
A and the higher order byte in B.
The 8051 has DIV instruction unlike many other 8-bit processors. DIV instruction
divides the unsigned 8-bit integers in A and B. The accumulator receives the integer part of the
quotient and the register B receives the remainder.
8.4 Procedure:
i) Enter the opcodes from memory location 4200
ii) Execute the program
iii) Check for the result at 4100 and 4101
Using the accumulator, subtraction is performed and the result is stored. Immediate
addressing is employed. The SUBB instruction drives the result in the accumulator.
8.5 Program
Addition without carry:
MEMORY
LABEL MNEMONICS OP CODE
ADDRESS COMMENTS
CLR C
MOV A,#data1
ADD A, #data2
MOV DPTR, #4500H
MOVX @DPTR, A
LOOP SJMP LOOP
Observation
INPUT OUTPUT
Address Data Address Data
Subtraction
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
SUBB A, #data2
MOV DPTR, #4500H
MOVX @DPTR, A
LOOP SJMP LOOP
Observation
INPUT OUTPUT
Address Data Address Data
Multiplication
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
MOV B,#data2
MUL AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
LOOP SJMP LOOP
Observation
INPUT OUTPUT
Address Data Address Data
Division
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
MOV B,#data2
DIV AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
LOOP SJMP LOOP
Observation
INPUT OUTPUT
Address Data Address Data
8.6 Pre-Lab Questions:
1. Write the features of 8051 Microcontroller.
2. Draw the PSW format for 8051 Microcontroller
3. List out the special function registers of 8051.
8.7 Post-Lab Questions:
1. Show the status of CY,AC and P flags after the execution of following instructions
MOV A, #9CH
ADD A, #64H
2. Simulate the programs using edsim51 software.