VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
5. PROGRAMMING USING ARITHMETIC OPERATION INSTRUCTIONS OF
8051MICROCONTROLLER
5(A): ADDITION OF TWO 8-BIT NUMBERS
AIM:
To develop an assembly language program to add the two 8-bit numbers using 8051
Microcontroller instruction set.
Theory:
Arithmetic Instructions
The arithmetic operations of 8051 include increment, decrement, addition, subtraction,
multiplication, division and decimal operations. Like logical operations, arithmetic
operations also affect flags. Let us see the instructions which affect flags before going to
study arithmetic instructions in detail.
Flags
We know that, the 8051 has four flags: the carry (C), Auxiliary Carry (AC), Overflow (OV),
and parity (P). The C, AC and OV flags are arithmetic flags. They are set to 1 or cleared to 0
automatically, depending on the result of instructions, shown in table.
Incrementing and Decrementing
Incrementing and decrementing instructions allow addition and subtraction of 1 from a
given number. These instructions do not affect C, AC and OV flags. The table lists the
increment and decrement instructions.
Subtraction
The 8051 supports one subtraction instruction SUBB. The SUBB (subtract with borrow)
instruction subtracts the byte variable indicated and the contents of the carry flag together
from the accumulator, and puts the result back in the accumulator. The carry flag serves as
a “Borrow required” flag during subtraction operations when a greater value is subtracted
from a lesser value (as in subtracting 5 from 1) requiring a borrow into the highest order
bit, the carry flag is set; otherwise it is cleared.
APPARATUS REQUIRED:
1. 8051 Microcontroller Kit
2. 5v DC Power supply.
10211EE305 1
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
ALGORITHM:
1. Clear c- register for carry.
2. Move the first data to accumulator.
3. Add the second data with accumulator.
4. Store the sum in memory pointed by DPTR.
PROGRAM:
ADDRESS LABLE MNEMONICS OP-CODE COMMENTS
6100 CLC C C3
6101 MOV A,#DATA1 74,04
6103 ADD A,#DATA2 24,02
6105 MOV DPTR,#6500H 90,65,00
6108 MOVX @DPTR,A FO
6109 Loop SJMP LOOP 80,FE
OBSERVATION:
INPUT OUTPUT
Address Data Address Data
6102 6500
6103
RESULT:
Thus the assembly language program to add the two 8-bit numbers using 8051
Microcontroller instruction set was developed and executed successfully.
Questions:
1. Name fore major differences between microprocessor and microcontroller?
2. What do you mean by internal mode of programming?
3. Write most unusual application of a microcontroller seen actually for seal?
4. Size of internal RAM?
5. Internal ROM size in 8051, 8031?
10211EE305 2
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
5(B): SUBTRACTION OF TWO 8-BIT NUMBERS
AIM:
To develop an assembly language program to subtract the two 8-bit numbers using
8051 Microcontroller instruction set.
APPARATUS REQUIRED:
i. 8051 Microcontroller kit
ii. 5v DC Power supply.
ALGORITHM:
1. Clear c- register for carry.
2. Move the first data to accumulator.
3. Subtract the second data with accumulator.
4. Store the difference in memory pointed by DPTR.
PROGRAM:
ADDRESS LABLE MNEMONICS OP-CODE COMMENTS
6100 CLC C C3
6101 MOV A,#DATA1 74,04
6103 SUBB A,#DATA2 94,02
6105 MOV DPTR,#6500H 90,65,00
6108 MOVX @DPTR,A FO
6109 Loop SJMP LOOP 80,FE
OBSERVATION:
INPUT OUTPUT
Address Data Address Data
6102 6500
6103
10211EE305 3
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
RESULT:
Thus the assembly language program to subtract the two 8-bit numbers using
8051 Microcontroller instruction set was developed and executed successfully.
10211EE305 4
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
5(C): MULTIPLICATION OF TWO 8-BIT NUMBERS
AIM:
To develop an assembly language program to multiply the two 8-bit numbers using
8051 Microcontroller instruction set.
APPARATUS REQUIRED:
i. 8051 microcontroller kit
ii. 5v DC Power supply.
ALGORITHM:
1. Clear c- register for carry.
2. Move the first data to accumulator.
3. Move second data to b register.
4. Multiply second data to accumulator.
5. The higher order of result is in B-register.
6. The lower adder of result is in A-register
PROGRAM:
ADDRESS LABLE MNEMONICS OP-CODE COMMENTS
6100 CLC C C3
6101 MOV A,#DATA1 74,04
6103 MOV B,#DATA2 75,F0,02
6106 MUL A,B A4
6107 MOV DPTR,#6500H 90,65,00
610A MOVX @DPTR,A F0
610B INC DPTR A3
610C MOV A,B E5,F0
610E MOVX @DPTR,A F0
610F Loop SJMP LOOP 80,FE
10211EE305 5
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
OBSERVATION:
INPUT OUTPUT
Address Data Address Data
6102 6500
6103 6051
RESULT:
Thus the assembly language program to multiply the two 8-bit numbers using
8051 Microcontroller instruction set was developed and executed successfully.
Lab Questions:
1. Execution time of single cycle instruction for a 6 MHz crystal?
2. Write 16-bit data addressing registers and their function?
3. Draw and explain PSW (program status word)?
4. Which register holds the serial data interrupt bits T1 and R1?
5. Address of stack when 8051 is reset?
10211EE305 6
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
5(D): DIVISION OF TWO 8-BIT NUMBERS
AIM:
To develop an assembly language program to divide the two 8-bit numbers using
8051 Microcontroller instruction set.
APPARATUS REQUIRED:
1. 8051 Microcontroller kit
2. 5v DC Power supply.
ALGORITHM:
1. Clear c- register for carry.
2. Move the first data to accumulator.
3. Move second data to b register.
4. Divide second data to accumulator.
5. The higher order of result is in B-register.
6. The lower adder of result is in A-register
PROGRAM:
ADDRESS LABLE MNEMONICS OP-CODE COMMENTS
6100 CLC C C3
6101 MOV A,#DATA1 74,04
6103 MOV B,#DATA2 75,F0,02
6106 DIV A,B 84
6107 MOV DPTR,#6500H 90,65,00
610A MOVX @DPTR,A F0
610B INC DPTR A3
610C MOV A,B E5,F0
610E MOVX @DPTR,A F0
610F Loop SJMP LOOP 80,FE
10211EE305 7
VELTECH UNIVERSITY EEE DEPARTMENT MP&MC LAB
OBSERVATION:
INPUT OUTPUT
Address Data Address Data
6102 6500
6103 6051
RESULT:
Thus the assembly language program to divide the two 8-bit numbers using 8051
Microcontroller instruction set was developed and executed successfully.
Lab Questions:
1. Register that can be used for division?
2. Write the register banks and their address?
3. Why a low address byte latch for external memory is needed?
4. How an I/O pin can be both an input and output?
5. Which port has no alternate function?
10211EE305 8