16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART FOR ADDITION
START
Move the first number to A
register
Add the second number with the contents of
the accumulator
Initialize data pointer.
Move the result from the
accumulator to the data pointer.
STOP
Page 40
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
Ex.No: PROGRAM USING ARITHMETIC INSTRUCTIONS OF 8051
OBJECTIVE
To write an assembly language program to add, subtract, multiply and divide two 8-bit &
16-bit numbers using 8051 microcontroller.
LEARNING OUTCOMES
After the completion of the experiment, the students are expected to
Understand the programming concept and usage of Arithmetic instructions
Determine the single byte Subtraction value.
SYSTEM AND SOFTWARE TOOLS REQUIRED
1. 8051 Microcontroller Kit
2. Keyboard
PRE LAB WORK
ALGORITHM FOR ADDITION
1. Start the program.
2. Move the first number to A register.
3. Add the second number with the contents of the accumulator.
4. Initialize data pointer address.
5. Move the result from the accumulator to the data pointer.
6. Stop the program.
Page 41
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
IN LAB WORK
PROGRAM
ADDRESS LABEL MNEMONICS HEXCODES COMMENTS
START CLR C
MOV A,#04
ADDC A,#05
MOV DPTR,#4500
MOVX @DPTR,A
STOP SJMP 4109
INPUT
OUTPUT
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART FOR SUBTRACTION
START
Move the first number to A
register
Move the second number to register R1.
Subtract thesecond number ad borrow with
the contents of the accumulator
Initialize data pointer.
Move the result from the
accumulator to the data pointer.
STOP
Page 42
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
PRE LAB WORK
ALGORITHM FOR 8 BIT SUBTRACTION
1. Start the program.
2. Move the first number to A register.
3. Subtract the second number with the contents of the accumulator.
4. Initialize data pointer address.
5. Move the result from the accumulator to the data pointer.
6. Stop the program.
IN LAB WORK
PROGRAM
ADDRESS LABEL MNEMONICS HEXCODES COMMENTS
START CLR C
MOV A,#08
MOV R1,#04
SUBB A,R1
MOV DPTR,#4500
MOVX @DPTR,A
STOP SJMP 410A
INPUT
OUTPUT
Page 43
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART
START
Move the first number to A register
Move the first number to B register
Multiply the contents of A and B register
Initialize data pointer.
Move the result from the accumulator
to the data pointer.
Incrementthe data pointer.
Move the content of the B register to the accumulator.
Moves the contents of the
accumulator to the data pointer.
STOP
Page 44
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
PRE LAB WORK
ALGORITHM FOR 8 BIT MULTIPLICATION
1. Start the program.
2. Move the first number to A register.
3. Move the first number to B register.
4. Multiply the contents of A and B register.
5. Initialize data pointer address.
6. Move the result from the accumulator to the data pointer.
7. Increment the data pointer.
8. Move the content of the B register to the accumulator.
9. Moves the contents of the accumulator to the data pointer.
10. Stop the program.
IN LAB WORK
PROGRAM
ADDRESS LABEL MNEMONICS HEXCODES COMMENTS
START MOV A,#02
MOV B,#01
MUL AB
MOV DPTR,#4500
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
STOP SJMP 410E
INPUT OUTPUT
Page 45
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART
START
Move the first number to A register
Move the first number to B register
Divide the contents of A and B register
Initialize data pointer.
Move the result from the accumulator
to the data pointer.
Incrementthe data pointer.
Move the content of the B register to the accumulator.
Moves the contents of the
accumulator to the data pointer.
STOP
Page 46
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
PRE LAB WORK
ALGORITHM FOR 8 BIT DIVISION
1. Start the program.
2. Move the first number to A register.
3. Move the first number to B register.
4. Divide the contents of A and B register.
5. Initialize data pointer address.
6. Move the result from the accumulator to the data pointer.
7. Increment the data pointer.
8. Move the content of the B register to the accumulator.
9. Moves the contents of the accumulator to the data pointer.
10. Stop the program.
IN LAB WORK
PROGRAM
ADDRESS LABEL MNEMONICS HEXCODES COMMENTS
START MOV A,#02
MOV B,#01
DIV AB
MOV DPTR,#4500
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
STOP SJMP 410E
INPUT
OUTPUT
Page 47
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART
Start
Load LSB of 1st data to A register
Add LSB of 2nd data with A register
Initialize the data pointer
Store the result in memory
Increment the memory pointer
Load MSB of 1st data to A register
Add MSB of 2nd data with A
register
Store the result in memory
Stop
Page 48
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
PRE LAB WORK
ALGORITHM FOR 16 BIT ADDITION
1. Start the program.
2. Get the LSB of the first operand in A register.
3. Add the LSB of second operand with A register.
4. Initialize data pointer and store the result in memory.
5. Increment the data pointer and get the MSB of the first operand in A register.
6. Add the MSB of second operand with A register.
7. Move the result from the accumulator to the data pointer.
8. Stop the program.
IN LAB WORK
PROGRAM
ADDRESS LABEL MNEMONICS HEXCODES COMMENTS
CLR C
MOV A,#20
ADD A,#52
MOV DPTR,#4200
MOV X@DPTR,A
INC DPTR
MOV A,#12
ADD A,#56
MOV X@DPTR,A
SJMP 410F
Page 49
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
INPUT
OUTPUT
Page 50
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
FLOWCHART
Start
Load LSB of 1st data to A register
Subtract LSB of 2nd data with A
register
Initialize the data pointer
Store the result in memory
Increment the memory pointer
Load MSB of 1st data to A register
Subtract MSB of 2nd data with A
register
Store the result in memory
Stop
Page 51
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
PRE LAB WORK
ALGORITHM FOR 16 BIT SUBTRACTIONS
1. Start the program.
2. Get the LSB of the first operand in A register.
3. Subtract the LSB of second operand with A register.
4. Initialize data pointer and store the result in memory.
5. Increment the data pointer and get the MSB of the first operand in A register.
6. Subtract the MSB of second operand with A register.
7. Move the result from the accumulator to the data pointer.
8. Stop the program.
EXPERIMENTAL SETUP
POST LAB WORK
DISCUSSION OF RESULTS
1. Illustrate the difference between clock frequency and scan frequency?
2. How the program memory is organized in 8051 base d system?
Page 52
Department of ICE, Sri Krishna College of Technology
16IC313/Microprocessors and Microcontrollers Lab
VIVA VOCE
1. Name the five interrupt sources of 8051?
2. Explain the contents of the accumulator after the execution of the following program
segments:
3. Write a program to load accumulator A, DPH and DPL with 30H.
4. What is the difference between the Microprocessors and Microcontrollers?
RESULT
Thus the programs to add, subtract, multiply and divide two 8-bit numbers using 8051
microcontroller is executed and the outputs are verified.
Page 53
Department of ICE, Sri Krishna College of Technology