0% found this document useful (0 votes)
170 views

Microcontroller Lab Manual

This document provides an overview of the Microcontroller Laboratory at the National Institute of Engineering including its vision, mission, program educational objectives, outcomes and list of experiments. It begins with an introduction to the 8051 microcontroller, describing its features, pin descriptions and memory organization. It also provides an introduction to the Keil software used for microcontroller programming.

Uploaded by

R A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views

Microcontroller Lab Manual

This document provides an overview of the Microcontroller Laboratory at the National Institute of Engineering including its vision, mission, program educational objectives, outcomes and list of experiments. It begins with an introduction to the 8051 microcontroller, describing its features, pin descriptions and memory organization. It also provides an introduction to the Keil software used for microcontroller programming.

Uploaded by

R A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

THE NATIONAL INSTITUTE OF

ENGINEERING
Manandvadi Road, Mysuru-08
(Autonomous Institution under VTU)

DEPARTMENT OF ELECTRICAL &


ELECTRONICS ENGINEERING

Laboratory Manual

Microcontroller Laboratory
Department of Electrical and Electronics Engineering

Department Vision
The department will be an internationally recognized centre of excellence imparting
quality education in electrical engineering for the benefit of academia, industry and society at
large.

Department Mission
M1: Impart quality education in electrical and electronics engineering through theory and its
applications by dedicated and competent faculty.

M2: Nurture creative thinking and competence leading to innovation and technological
growth in the overall ambit of electrical engineering

M3: Strengthen industry-institute interaction to inculcate best engineering practices for


sustainable development of the society

Program Educational Objectives


PEO1: Graduates will be competitive and excel in electrical industry and other
organizations
PEO2:Graduates will pursue higher education and will be competent in their chosen
domain
PEO3: Graduates willdemonstrate leadership qualities with professional standards for
sustainable development of society

PROGRAM OUTCOMES

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals and an engineering specialization to the solution of complex
engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze


complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety and the cultural,
societal and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and


research methods including design of experiments, analysis and interpretation of data
and synthesis of the information to provide valid conclusions.

5. Modern tool usage: Create, select and apply appropriate techniques, resources and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional


engineering solutions in societal and environmental contexts and demonstrate the
knowledge of and need for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

9. Individual and team work: Function effectively as an individual and as a member or


leader in diverse teams and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with


the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.

12. Life-long learning: Recognize the need for and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
Program Specific Outcomes
Our Electrical and Electronics Engineering graduates will have the ability to:

• PSO1: Apply the knowledge of Basic Sciences, Electrical and Electronics


Engineering and Computer Engineering to analyze, design and solve real world
problems in the domain of Electrical Engineering.

• PSO2: Use and apply state-of-the-art tools to solve problems in the field of Electrical
Engineering .

• PSO3: Be a team member and leader with awareness to professional engineering


practice and capable of lifelong learning to serve society.
Microcontroller Lab (0-0-3)
Sub Code :EE0108 CIE :25Marks
Hrs/Week : 03 Hrs SET: 25Marks

Course Outcomes

On successful completion of the course students will be able to:

1. Write and execute programs using instruction set of 8051.


2. Interface LCD, KEYPAD with microcontroller.
3. Demonstrate speed control of stepper motor and DC motor control.
4. Generate waveforms by interfacing DAC with microcontroller.

List of experiments:

1.Programs for-Block move, Exchange, Sorting, Finding largest element in an array.


2.Programs for-Addition/subtraction, multiplication and division, square, Cube –(16 bits Arithmetic
operations –bitaddressable).
3.Programs forrealizing Counters.
4.Programs to illustrate the use of Boolean and Logical Instructions (Bit manipulations).
5.Conditional CALL and RETURN.
6.Programs to demonstrate Code conversion: BCD –ASCII; ASCII –Decimal; Decimal -ASCII; HEX-
Decimal and Decimal –HEX.
7.Alphanumeric LCD panel and Hex keypad input interface to 8051/ATMEL.
8.Generatedifferent waveforms like Sine, Square, Triangular, Ramp etc. using DAC.
9.Steppermotor control using 8051/ATMEC
10.DC motor control using 8051/ATMEL
Microcontroller Basics

A microcontroller is a computer-on-a-chip, or a single-chip computer. Microsuggests that the


device is small, and controller tells that the device might be used to control objects,
processes, or events. Another term to describe a microcontroller is embedded controller,
because the microcontroller and its support circuits are often built into, or embedded in, the
devices they control.

Introduction to 8051 8-bit microcontroller:

Intel Corporation is first company who presented 8051 microcontroller in market. It is 8 bit
microcontroller. It have on chip 128 bytes of RAM, 4K bytes ROM, two timers, one serial
port and four general purpose input/output ports. Each port has 8 bit register.

Some of the features that have made the 8051 popular are:

 4 KB on chip program memory.


 128 bytes on chip data memory(RAM)
o 32 bytes devoted to register banks
o 16 bytes of bit-addressable memory
o 80 bytes of general-purpose memory
 4 register banks.
 128 user defined software flags.
 8-bit data bus
 16-bit address bus
 16 bit timers (usually 2, but may have more, or less).
 3 internal and 2 external interrupts.
 Bit as well as byte addressable RAM area of 16 bytes.
 Four 8-bit ports, (short models have two 8-bit ports).
 16-bit program counter and data pointer.
 1 Microsecond instruction cycle with 12 MHz Crystal.

8051 Pin description:


 Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is
internally pulled up, bi-directional I/O port.

 Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.

 Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like interrupts, timer
input, control signals, serial communication signals RxD and TxD, etc.

 Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system clock.

 Pin 20 − This pin provides the power supply to the circuit.

 Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address bus signals
are also multiplexed using this port.

 Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a signal from the
external program memory.

 Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable the
external memory interfacing.

 Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex the
address-data signal of port.

 Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address and data
bus signals are multiplexed using this port.

 Pin 40 − This pin is used to provide power supply to the circuit.

Block diagram of 8051:


8051 memory organization:
INTRODUCTION TO KEIL SOFTWARE
Keil’s µVision IDE provides a powerful, easy to use and easy to learn environment
for developing embedded applications. They include the components to create,
debug, and assemble C/C++ source files, and incorporate simulation for
microcontrollers and related peripherals. The Keil µVision Integrated Development
Environment (µVision IDE) supports three major microcontroller architectures and
sustains the development of a wide range of applications. The microcontroller
architecture supported are 8-bit (classic and extended 8051), 16-bit (Infineon C166,
XE166, XC2000) and 32-bit (ARM7 and ARM9 based) devices.
The Keil C51 Compiler and the Keil Linker/Locator provide optimum 8051
architecture support with the following features and C language extensions.
 Interrupt functions with register bank support are written directly in C.
 Bit and bit-addressable variables for optimal Boolean data type support.
 Compile-time stack with data overlaying uses direct memory access and gives
high-speed code with little overhead compared to assembly programming.
 Reentrant functions for usage by multiple interrupt or task threats.
 Generic and memory-specific pointers provide flexible memory access.
 Linker Code Packing gives utmost code density by reusing identical program
sequences.
 Code and Variable Banking expand the physical memory address space
 Absolute Variable Locating enables peripheral access and memory sharing
KEIL COMPILER SETTINGS FOR ATMEL 89C51ED2 PROCESSOR

1. Click on KeiluVision 3 Icon. On Project menu click New Project.

2. Create New Project menu will appear with file directory. Create a new folder say
test. Choose the path and the folder name where you want your project. In this
case ‘test’ folder is chosen. In the filename box, key in the project name . Here it is
taken as test. Click on Save button. Now the project test will be saved in test folder.
3. After step 2 is completed successfully next screen for choosing the target will
appear. This is to enable the user to select the target CPU. Select Device for
Target ‘Target 1’ menu will appear with Manufacturing company names.
4. Choose Atmel name and under this menu choose AT89C51ED2.

5. Copy Standard 8051 Startup Code to Project and add file to project willappear.
Click No.
6. Place the mouse cursor on Target in the workspace. Right click the mouse.
Options for Target Target 1 will appear.

7. Select the option by clicking the mouse. Options for Target ‘Target1’ menu will
appear. Here enter Xtal frequency as 11.0592 and tick Use on-chip ROM and
Use On-chip XRAM check boxes.
8. Move on to Output tab. Here tick Create hex file as shown below. This is will
make the compiler linker to create the hex file which will be downloaded to
evaluation board for execution.

9. Expand Target by clicking on ‘+’ to see Source Group 1. This is done to include
‘.asm’ source file or/and Assembler source file to project.
10. Create a ‘.c’ source file by clicking on File menu and choosing Newsub menu.

11. A edit text screen Text1 will appear.


12. Go to File Menu -- > Save and save it as test.asm

13. Now we can add this ‘.c’ source file to the project by right clicking on source and
choosing Add files to Group ‘Source Group 1’
14. A file browser dialog box will appear. You can choose the drive, directory and
file to add to project. Here we are pointing to test.asmfile to add. Click on Add
button. Now this file is added to the project.

15. This file now will appear on the screen

16. Click on Project Menu chooseTranslate to compile the .asmsource file(s).


17. Click on Project Menu choose Build target and check for syntax errors

18. Again in the DEBUG menu select START/STOP debug session in the
disassembly window Program Code will be displayed. in the register space,
Contents of registers are visible.

19. To view memory, got to VIEW and select MEMORY WINDOW. Type the address
of memory location in address window and see its content.C:0X00=CODE
MEMORY, I: 0X00=INTERNAL DATA MEMORY, X: 0X00=EXTERNAL
MEMORY. if there is a need to give input to the program that can be done at this
stage.

20. Click RUN/STEP RUN in the DEBUG menu depending on the requirement. And
see the result in the Specified memory location and also in registers.
ASSEMBLY LANGUAGE PROGRAMS

Programs on Addressing modes:


1. Write a program to store content value (8-bit) in the internal RAM location starting from 30h to
34h.

a. Using direct addressing mode


b. Using indirect addressing mode without loop.

a.Using direct addressing mode

Label Mnemonic Comments

MOV A,#40h Get data 40h to Accumulator.

MOV 30h,A Copy the contents of register A to the 30h address

MOV 31h,A Copy the contents of register A to the 31h address

MOV 32h,A Copy the contents of register A to the 32h address

MOV 33h,A Copy the contents of register A to the 33h address

MOV 34h,A Copy the contents of register A to the 34h address

END

b. Using indirect addressing mode without loop.


Label Mnemonic Comments

MOV A,#40h Get data 40h to Accumulator.

MOV R0,#30h Copt the address data 30h into register R0

MOV @R0,A Copy the contents of A to address in R0

MOV R0,#31h Copt the address data 31h into register R0

MOV @R0,A Copy the contents of A to address in R0

MOV R0,#32h Copt the address data 32h into register R0

MOV @R0,A Copy the contents of A to address in R0

MOV R0,#33h Copt the address data 33h into register R0

MOV @R0,A Copy the contents of A to address in R0

MOV R0,#34h Copt the address data 34h into register R0

MOV @R0,A Copy the contents of A to address in R0

END
2. Program to transfer a block of data bytes starting from the Memory location 30h to another block starting from the
Memory location 40h.

Label Mnemonic Comments

MOV R0,#30h Point R0 to the source block.

MOV R1,#40h Point R1 to the destination block.

MOV R2,#Count Count of the data bytes to be transferred.

Loop: MOV A,@R0 Get the 1st data into A register.

MOV@R1,A Move the 1st data in A to the destination block.

INC R0 Increment the source addr.

INC R1 Increment the destination addr

DJNZ R2, Loop Repeat the above process till R2 goes to 0.

Loop1: SJMP Loop1

END

3. Program to store a constant value (8-bit) in the external RAM location starting from 9000h to 9004h

Label Mnemonic Comments

MOV R0, #Count Count of the data bytes to be transferred.

MOV A,#0ABh Get the data ABh to accumulator

MOV DPTR,#9000h DPTR being pointed to destination address

UP: MOVX @DPTR,A Copy the data in reg A to DPTR

INC DPTR Increment the destination address

DZNZ R2,UP Check whether the count is zero, if not jump to


label UP else END
END

4. Program to exchange the contents of two internal data memory location.

Label Mnemonic Comments

MOV A,40h Get the data to A register from memory location


40h.
XCH A,41h
Interchange the contents in A and 41h location.
MOV 40h,A
Copy the contents of 41 in A register to 40h
Loop: SJMP Loop location.
5. Program to exchange the contents of the registers.

Label Mnemonic Comments

MOV R0,#data1 Get data1 to R0.

MOV R1,#data2 Get data2 to R1.

MOV A,R0 Get the data1 to accumulator.

XCH A,R1 Interchange contents of A and R1.

MOV R0,A Copy the same to R0.

Loop: SJMP Loop

END

6. Program to interchange the contents of two external memory locations.

Label Mnemonic Comments

MOV DPTR,#16 BitAddr Point DPTR to the source addr.

MOVX A,@DPTR Get the data from the addr to A reg.

MOV R0,A Copy the data in A to reg R0.

INC DPTR Increment the source addr.

MOVX A,@DPTR Get the 2nd data from the addr.

XCH A,R0 Exchange the contents of A and r0.

MOVX @DPTR,A Store the data in A to the addr pointed by DPTR

DEC 82h Decrement the lower byte of DPTR.

MOV A,R0 Move the data in R0 to A reg.

MOVX @DPTR,A Copy the data in A reg to the addr pointed by


DPTR.
Loop: SJMP Loop

END
7. Program to transfer block of data bytes starting from memory location 9000h to another block starting from the memory
location 9100h in external memory location.

Label Mnemonic Comments

MOV R2,#Count Load the count of data bytes to be transferred.

MOV DPTR,#9100h DPTR being pointed to the destination address.

MOV R0,82h Copy the contents of the DPTR i.e DPL and DPH into
R0 and R1.
MOV R1,83h

MOV DPTR,#9000h DPTR pointed to the source address.

Loop: MOVX A,@DPTR Copy the 1st data from the source address pointed by
DPTR.

Increment the DPTR to point to the next address in the


INC DPTR source block.

PUSH 82h Save the incremented source address in DPTR on to the

stack.
PUSH 83h

MOV 82h,R0 Load the lower byte of destination address in DPL.

MOV 83h,R1 Load the higher byte of destination address in DPH.

MOVX @DPTR,A Copy the data in A to the address pointed by DPTR.

INC DPTR Increment the DPTR to point to the next address in the
destination block.

MOV R0,82h
Copy the contents of the DPTR into R0 and R1

MOV R1,83h registers.

POP 83h Retrieve the source address from the stack to the
DPTR.
POP 82 h
Repeat the above process till all the data bytes are
DJNZ R2, Loop transferred.

Loop1: SJMP Loop1

END
8. Program to interchange the block of data bytes present in internal memory.

Label Mnemonic Comments

MOV R2, #COUNT Load the count of the data bytes.

MOV R0,# block1 ADDR Point R0 to source address

MOV R1,# block2 ADDR Point R1 to dest address

Loop: MOV A,@R0 Get the 1st data byte from block1.

XCH A,@R1 Exchange the 1st data bytes of both the blocks.

MOV @R0,A Increment both R0 and R1 to point to the address


of the next data bytes.
INC R0
Check whether the count is zero, if not loop back
INC R1 else halt.

DJNZ R2, Loop

Loop1: SJMP Loop1

END

9. Program to transfer data from the external memory starting from 9040h to 9044h to stack memory from 71h to 75h and
transfer to internal RAM starting from 30h to 34h using PUSH and POP instruction.

Label Mnemonic Comments

MOV SP, #70H Point SP to the destination address

MOV R3,#05H Load the count of data bytes for PUSH

MOV R2,#05H Load the count of data bytes for POP

MOV R0,#34H Point R0 to destination address

MOV DPTR,#9040H Point DPTR to the source address

UP: MOVX A,@DPTR Get the data from DPTR address to A

PUSH 0E0H Increment & PUSH the content pointed by SP to0E0h

INC DPTR Increment DPTR

DJNZ R2,UP Check whether the count is zero if not back to label
Up

UP1: POP 0E0H


Retrieve the data from destination and decrement
MOV @R0,A Copy the content of A to address pointed by R0

DEC R0 Decrement R0

DJNZ R3,UP1 Check whether the count is zero if not go back to


label or else end
END

Arithmetic Programming:

1. Program to add ‘n’ 8 bit binary numbers present in the internal memory location.

Label Mnemonic Comments

MOV R0,#SOURCE ADDR Use register R0 to point to the source addr.

MOV R1,#COUNT Load the count of numbers in R1

MOV 40h,#00 Clear the addresses 40 and 41

MOV 41h,#00

MOV A,@R0 Get the data from the addr pointed by R0.

Back: ADD A,40h Add the contents of A with addr 40

MOV 40h,A Copy the result into addr 40

JNC Next Check whether carry is generated. If no, go


ahead. Else increment 41.
INC 41h

Next: INC R0 Increment the addr pointed by R0.

DJNZ R1, Back Continue the above operation till the count
becomes zero and halt.
Loop: SJMP Loop

END
2. Program to add two 8 bit binary numbers present in internal memory location store the Sum in next consecutive
memory location.

Label Mnemonic Comments

MOV R1,#00 Clear the contents of register R1.

MOV R0,#SRC ADDR Point register R0 to the source addr.

MOV A,@R0 Get the 1st number in Accumulator.

INC R0 Increment the source address.

ADD A,@R0 Add the 1st and the 2nd data byte.

JNC Next Check whether there is a carry.

INC R1 If there’s a carry increment the R1.

INC R0 Increment the source addr.

Next: MOV @R0,A Copy the sum to the addrs pointed by R0.

INC R0 Increment the addr pointed by R0.

MOV A,R1 Get the carry in R1 to A register.

MOV @R0,A Store the carry in the next location.

SJMP Loop

Loop: END

3. Program to add two ‘n’ byte numbers.

Label Mnemonic Comments

CLR C Clear the carry.

MOV R2, # COUNT Load the count in R2.

MOV R3, # 00 Clear the register R3.

MOV R0, #SRC ADDR Use R0 to point to the source addr.

MOV R1, #DEST ADDR Use R1 to point to the destaddr.

MOV DPTR,#RSLT ADDR Use DPTR to point to the addr where result is
stored.

MOV A,@R0 Get the 1st byte in accumulator.

Loop: ADDC A,@R1 Add the 1st byte with carry.


MOVX @DPTR,A Store the result in the addr pointed by DPTR.

INC R0 Increment the source address.

INC R1 Increment the destination address.

INC DPTR Increment addrs in DPTR.

DJNZ R2, Loop Check whether the count is zero if not loop back
else check for no carry. If carry, increment R3.
JNC Next
Get the carry in A register.
INC R3
Save the carry.
Next: MOV A,R3

MOVX @DPTR,A

Loop1: SJMP Loop1

END

4. Program to add two 8 bit BCD numbers.

Label Mnemonic Comments

MOV R0,# SRC ADDR Use the register to point to the source location.

MOV R1, #00 Clear the contents of register R1.

MOV A,@R0 Get the data from src location.

INC R0 Increment the source addr by 1

ADD A,@R0 Add the data bytes present in A and the address
pointed R0.

DA A Convert the result in A to its equivalent decimal


value.

Check whether there is a carry.


JNC Next
Copy the result in A to R2.
MOV R2,A
Copy the content of R1into A.
MOV A,R1
Add the accumulator content with data.
ADD A,#01

DA A Convert the result to its equivalent decimal value.

MOV R1,A Copy the result into R1.

MOV A,R2 Copy the content of R2 into A.


Next: MOV 40h,A Copy the data in A to the addr 40.

MOV 41h,R1 Copy the carry in R1 to the addr 41.

Loop: SJMP Loop

END

5. Program to add ‘n’ 8 bit BCD numbers.

Label Mnemonic Comments

MOV R2,# COUNT Load the count of number bytes in R2.

CLR A Clear the contents of the A register.

MOV R0,# SRC ADDR Get the source addr in R0.

MOV R1,# 00 Clear the contents of R1.

ADD A,@R0 Add the contents in A with the data present in the
address pointed by R0,

Back: DA A Convert the result to its equ decimal.

JNC Next Check whether there is a carry.

MOV R3,A Copy the content of A into R3 reg.

MOV A,R1 Clear the accumulator contents.

ADD A,#01 Add A regwith immediate value.

DA A Convert the result to its equ decimal.

MOV R1,A Copy the contents of the A to R1.

MOV A,R3 Copy the contents of R3 to A.

INC R0 Increment the address pointed by R0.

DJNZ R2, Back Check whether the count is 0.

Next: MOV 40h,A Save the contents of A in Addr 40.

MOV 41h,R1 Save the contents of R1 in Addr 41.

Loop: SJMP Loop

END
6. Program to perform 8 bit binary subtraction.

Label Mnemonic Comments

CLR C Clear the carry.

MOV R0, # SRC ADDR Get the source address into R0.

MOV R1, #00 Clear the R1 register.

MOV A, @R0 Get the 1st data into Accumulator.

INC R0 Increment the source addr by 1.

SUBB A,@R0 Subtract with borrow the data present in A with


the data at the addr

JNC Next Check for carry. If no go ahead.

INC R1 Increment the reg R1 if carry.

Next: INC R0 Increment R0 to point the next location.

MOV @R0, A Store the result.

INC R0 Increment R0 to next address.

MOV A,R1 Copy the content of R1 to A.

MOV @R0,A Store the carry.

Loop: SJMP Loop

END

7. Program to perform 8 bit subtraction by 1’s compliment method.

Label Mnemonic Comments

MOV R0, # SRC ADDR Point reg Ro to the source addr.

MOV A,@R0 Get the 1stdatabye into A register.

INC R0 Increment the R0 to next address.

CPL A Compliment the contents of A reg.

ADD A,@ R0 Add the content of A with the data present in the
addrs pointed by R0.

JNC Next. Check whether there is a carry.

ADD A, #01 I there is a carry add A with 1.


Next: INC R0 Increment the addr pointed by R0.

MOV @R0, A Store the result.

Loop: SJMP Loop

END

8. Program to perform 8 bit binary subtraction by 2’s compliment method.

Label Mnemonic Comments

MOV R0, # SRC ADDR Use R0 to point to the source addr.

MOV A, @R0 Get the data into the A register.

INC R0 Increment R0 to point the next addr.

CPL A Compliment the contents of A.

ADD A,# 01 Convert the content in A to 2’s compliment.

ADD A,@R0 Add the content in A with the data at the addr
pointed by R0.

INC R0 Increment the addr pointed by R0.

MOV @R0, A Store the result.

Loop: SJMP Loop

END

9. Program to perform 8 bit binary multiplication

Label Mnemonic Comments

MOV R0,#SRC ADDR Point R0 to the source location.

MOV A, @R0 Get the data into A from the addr pointed by R0.

INC R0 Increment R0 to point to the next addr.

MOV B,@R0 Get the next data to register B.

MUL AB Perform multiplication.

INC R0 Increment the addr pointed by R0.


MOV @R0,A Copy the lower byte of the result.

INC R0 Increment the addr to point the next location.

MOV @R0, B Copy the higher byte of the result.

Loop: SJMP Loop

END

10. Program to perform 16 bit binary multiplication.

Label Mnemonic Comments

MOV DPTR,# 9000h Use DPTR to point to the location where output isstored.

MOV R4,# 00 Clear the content of reg R4.

MOV R0, #30h Point reg R0 to the source addr1.

MOV R1,# 40h Point reg R1 to the source addr2

MOV A,@ R0 Get the data from source addr1.

MOV 0F0h,@R1 Get the 2nd data from source addr2.

MUL AB Multiply the data in A and B reg.

MOVX @DPTR, A Copy the lower byte of the result in the destaddr pointed by
DPTR.

MOV R2,0F0h Copy the data in B reg to R2 reg.

INC R1 Increment the source addr2.

MOV A,@R0 Get the data from source addr1 to A.

MOV 0F0h,@R1 Get the data from addr2 to the B reg.

MUL AB Multiply the data in A and B reg.

ADD A,R2 Add carry in R2 to the A reg.

MOV R2,A Copy the result in A reg to R2.

MOV A,0F0h Move the data in B to A reg.

ADDC A,#00 Add data 00 to A reg with Carry.

MOV R3,A Copy the data in A to reg R3.

INC R0 Increment the addr pointed by R0.

DEC R1 Decrement the addr pointed by R1.

MOV A,@R0 Get the next data from the addr to A


MOV 0F0h,@R1 Get the data from addr2 to B reg.

MUL AB Multiply the data present in A and B.

ADD A,R2 Add the data in R2 to the data in A.

INC DPTR Increment the destination addr.

MOVX @DPTR,A Copy the data in A to the destaddr.

MOV A, 0F0h Get the data present in B reg to A.

ADDC A,R3 Add with carry the contents of A and R3 reg.

MOV R3,A Move the data present in A to R3 reg

JNC Next If no Carry then jump to next.

INC R4 Increment the content of R4 reg.

Next: INC R1 Increment the source addr2.

MOV A,@R0 Get the data from addr1 to A reg.

MOV 0F0h,@R1 Get the data from addr2 to B reg.

MUL AB Multiply the data in A and B reg.

ADD A, R3 Add the content of A and R3 reg.

INC DPTR Increment the destaddr.

MOVX DPTR,A Copy the data in A reg to the addr pointed by DPTR.

MOV A,0F0h Copy the data present in reg B to A.

ADDC A, R4 Add the content of A and R4 with carry.

INC DPTR Increment the addr pointed by DPTR

MOVX @DPTR, A Store the carry in the addr.

Loop: SJMP Loop

END

11. Program to perform 8 bit binary division

Label Mnemonic Comments

MOV R0, # 40h Point reg R0 to the source addr.

MOV A,@ R0 Get the data to the A register from the source.

INC R0 Increment content in reg R0 and get the data to


reg B from addr in R0.
MOV 0F0h,@R0
DIV AB Divided content in A and B and store result in A
and B.

INC R0 Increment R0 and copy the accumulator contents


to the addr in reg R0.
MOV @R0, A
Increment R0 and copy the data from reg B into
INC R0
the addr in reg R0.
MOV @R0, 0F0h

Loop: SJMP Loop

END

12. Program to find the square root of a given number.

Label Mnemonic Comments

MOV R0, # 40h Point R0 to the source addr.

MOV 41h, # 00 Clear the content of addrloc 41..

Back : LCALL SQR Call the subroutine to get square of a given


number.

CJNE A, 40h, Next Compare the content of A and addrloc 40. if not

equal jump.

Stop : MOV 41h,A


Copy the content of the A reg to 41.
Loop: SJMP Loop
Check for the carry. If no stop else increment the
Next : JNC Stop content of addr 41.

INC 41h

SJMP Back

SQR: MOV A, @R0 Get the data into A reg from the location pointed
by R0.

MOV 0F0h, @R0 Copy the data from the addrloc pointed by R0 to
the B reg.

MUL AB Multiply the contents of A and B.

RET Return to the main prog.

END
13. Program to check whether the given byte is positive or negative.

Label Mnemonic Comments

MOV R1,# 00 Clear the contents of reg R1.

MOV R0,# 40h Point the reg R2 to the source addr.

MOV A,@R0 Get the data to the A reg from the addr pointed
by R0.

JNB 0E7h, Next Decrement the content of reg R1.

DEC R1 Increment the content of Reg R0.

Next : INC R0

MOV A,R1 Get the content of R1 to the A reg.

MOV @R0, A Copy the content of the A reg to the location


pointed by R0.
Loop: SJMP Loop

END

14. Program to find the cube root of a given number.

Label Mnemonic Comments

MOV R0,# 40h Point reg R0 to the source location.

INC R0 Increment the memory addr in R0.

Back : LCALL Cube Calling the sub programme cube.

CJNE A,40h, Next

Stop : MOV 43h,41h Get the data from 41h loc to 43h.

Next : SJMP Stop

JNC Stop Check for carry. If no jump to stop.

INC 41h Increment the content in 41h loc.

SJMP Back

Cube : MOV A,@R0 Get the content of memory location pointed by


R0 into A.

MOV B,@R0 Copy the same content to reg B.


MUL AB Multiply the content of reg A and B

MUL 0F0h,@ R0 Copy the data from loc pointed by R0.

MUL AB Perform the multiplication again.

RET Return to the calling prog.

15. Program to check whether the given byte is odd or even.

Label Mnemonic Comments

MOV R1, # 00 Clear the register R1.

MOV R0,# 40h Point reg R0 to the source addr.

MOV A,@R0 Get the data from the addr pointed by R0.

JNB 0E0h, Next Check the LSB. If not set jump.

DEC R1 If LSB is set decrement R1 contents.

Next: INC R0 If bit not set increment the contents of R0.

MOV A,R1 Copy the content of R1 into A reg.

MOV @R0,A Copy reg A contents to the location pointed by


R0.
Loop: SJMP Loop

END

Programs to illustrate the use of Boolean and Logical Instructions (Bit manipulations).
1. Program to count the number of 1’s and 0’s in a given byte.

Label Mnemonic Comments

MOV R0,#40h Point R0 to the source register.

MOV R1,#00 Clear the contents of register R1 and R2.

MOV R2,#00

MOV R3,#08 Load the count to the register R3.

MOV A,@R0 Get the data from the addr pointed R0.

Loop: RLC A Rotate the contents of A reg left through carry.


JNC Next Check for carry. If no go ahead.

INC R2 If there’s a carry increment the contents of R2.

SJMP Next1 Jump to the location next1.

Next: INC R1 Increment the contents of the R1 reg.

Next1: DJNZ R3, Loop Decrement the R3 register and check whether it
is zero.
INC R0
Increment the contents of R3 reg.
MOV 41h,R2
Copy the contents of register R1 and R2 to the
MOV 42h,R1 location 41 and 42h.

Loop1: SJMP Loop1

END

2. Program to check whether the given byte is 2 out of 5 code.

Label Mnemonic Comments

MOV R1,#00 Clear the contents of register R1.

MOV R0,#40h Point R0 to the source addr.

MOV R2,#05 Load the count in register R0.

MOV A,@R0 Get the data into A register from the addr pointed
by R0.

ANL A,#0E0h And the contents of A reg with the imm value.

JNZ Invalid If the result is not zero then the given byte is not
a 2 out of 5 code.

MOV A,@R0 Get the data into A reg from addr pointed by R0.

Loop: RRC A Rotate the data in accumulator right through


carry.

If carry bit is not set go to next.


JNC Next

INC R1 If there is a carry increment the R1.

Next: DJNZ R2, Loop Decrement the count and check for zero.

CJNE R1,#02, Invalid Compare the content of R1 with 02. ifits not
equal then its not a valid code.
MOV 41h,#00 If the code is valid move 00 to the location 41.

LCALL 03

Invalid: MOV 41h,#0FFh If the code is invalid move FF.

Loop1: SJMP Loop1

END

3. Program to check whether the given byte is nibble wise palindrome.

Label Mnemonic Comments

MOV R0,#40h Point R0 to the source addr.

MOV A,@R0 Get the data from the location pointed by R0.

SWAP A Swap the lower and higher nibbles of the


Accumulator.

Compare the data in A reg with the data present


CJNE A,40h,Notpal in addr 40.

INC R0 Increment the addr pointed by R0.

MOV @R0,#00 Move 00 to the addr pointed by R0 to indicate


the given data is nibble wise palindrome.
Loop: SJMP Loop

Move FF to the addrif it’s not a palindrome.


Notpal: INC R0

MOV @R0,#0FFh

Loop: SJMP Loop

4. Program to find the largest number in an array.

Label Mnemonic Comments

MOV R0,#40h Point register R0 to the source addr.

MOV R1,#(N-1) Load the count in the register R1.

MOV A,@R0 Get the data from the addr pointed by R0.

Loop: INC R0 Point R0 to the next addr.

MOV 50h,@R0 Copy the data present at the addr pointed by R0 to


location 50h.

CJNE A,50h, Next Compare the 1st and 2nd data. If they are not equal
jump to next.
SJMP Next1
Check whether there is a carry. If no, jump to next1
Next: JNC Next1

Next1: MOV A,@R0 Get the largest number in the A reg.

DJNZ R1,Loop Decrement the count and loop back till it goes to
zero.
MOV 50h,A
Loop1: Store the largest number in the location 50h.
SJMP Loop1

END

5. Program to find the smallest number in an array.

Label Mnemonic Comments

MOV R0,#40h Point reg R0 to the source addr.

MOV R1,#(N-1) Load the count in the register R1.

MOV A, @R0 Get the data from the addr pointed by R0.

Loop: INC R0 Increment the pointer to the next addr.

MOV 50h,@R0 Copy the data at the addr pointed by R0 to


location 50h.

Compare the 1st and 2nd data. If they are not equal
CJNE A,50h, Next jump to next.

SJMP Next1 Check whether there is a carry. If yes, jump to

Next: JC Next1 next1

MOV A,@R0 Get the smallest number in the A.

Next1: DJNZ R1, Loop Decrement the count and loop back

MOV 50h,A Store the smallest number in the location 50h.


Loop1:
SJMP Loop1
6. Program to arrange given set of numbers in ascending order.

Label Mnemonic Comments

MOV R2,#(N-1) Load the count of number of iterations in R2.

Loop1: MOV R0,#40 Point reg R0 to the source addr.

MOV R3,#(N-1) Load the number of comparison in R3.

Loop: MOV A,@R0 Get the data into A from the addr pointed by R0.

INC R0 Increment the addr pointed by R0.

MOV 50h,@R0 Copy the data form addr pointed by R0 to the


location 50h.

Compare the data in A with the data in addr 50h.


CJNE A,50h, Next if not equal jump.

SJMP NCHNG If they are equal, jump to NCHNG

Next: JC NCHNG If there is a carry, jump to NCHNG

MOV @R0,A Copy the data from the reg A to the location
pointed by R0.

Decrement the addr pointed by R0, and copy the


DEC R0 data at loc 50h to it.

MOV @R0,50h

INC R0 Increment the addr.

NCHNG: DJNZ R3, Loop Decrement the count of number of comparisons


and loop back if its not zero.

Decrement the count of number of iterations;


DJNZ R2, Loop1
continue till it goes to 0.
Loop2: SJMP Loop2
7. Program to arrange the given set of numbers in descending order.

Label Mnemonic Comments

MOV R2,#(N-1) Load the count of number of iterations in R2.

Loop1: MOV R0,#40h Point reg R0 to the source addr.

MOV R3,#(N-1) Load the number of comparison in R3.

Loop: MOV A,@R0 Get the data into A from the addr pointed by R0.

INC R0 Increment the addr pointed by R0.

MOV 50h,@R0 Copy the data form addr pointed by R0 to the


location 50h.

Compare the data in A with the data in addr 50h.


CJNE A,50h, Next if not equal jump.

SJMP NCHNG If they are equal, jump to NCHNG

Next: JC NCHNG If there is a carry, jump to NCHNG

MOV @R0,A Copy the data from the reg A to the location
pointed by R0.

DEC R0
Decrement the addr pointed by R0, and copy the
MOV @R0,50h data at loc 50h to it.

INC R0 Increment the addr.

NCHNG: DJNZ R3, Loop Repeat the above process till 3 goes to zero.

DJNZ R2, Loop1 Decrement the count of number of iterations;


continue till it goes to 0.
Loop2: SJMP Loop2
Programs to demonstrate Code conversion

1. Program to convert one digit binary number to its ASCII Equivalent.

Label Mnemonic Comments

MOV R0,#40h Point Reg R0 to the source addr.

MOV A,@R0 Get data from the addr pointed by R0.

Check whether the data in A with data 09. If


CJNE A,#09,Next

equal jump next.

SJMP Small If equal jump to small.


Next:
JC Small If there is a carry jump to small.
ADD A,#07h Add the content in A with data 07h.

ADD A,#30h Add the data in A with data 30h


Small:
INC R0 Increment the addr pointed by R0.

MOV @R0,A Copy the data in A to the addr.

SJMP Loop
Loop:

2. Program to convert 8 bit ASCII code to its binary equivalent.

Label Mnemonic Comments

CLR C Clear the carry.

MOV R0,#40h Point Reg R0 to the source addr.

MOV A,@R0 Get the data from the addr to A reg.

CJNE A,#39h,Next Compare the data with 39. If not equal jump to
next.

SJMP Small Else jump to label small.

Next: JC Small If there is a carry jump to small.

SUBB A,#07 Subtract A reg by 07 with borrow.


Small: CLR C Clear the carry.

SUBB A,#30h Subtract A reg by 30h with borrow.

INC R0 Increment the addr pointed by R0.

MOV @R0,A Move the data in A reg to the addr.

Loop: SJMP Loop

3. Program to convert 8 bit BCD to its ASCII equivalent.

Label Mnemonic Comments

MOV R0,#40h Point register R0 to the source addr.

MOV A,@R0 Get the data from the addr pointed by R0.

MOV B,A Copy the data in A reg to B.

ANL A,#0Fh AND the data in A with data 0F.

ADD A,#30h Add the content of A reg with 30h.

INC R0 Increment the addr pointed by R0.

MOV @R0,A Copy the data present in A reg to the addr


pointed by R0.

MOV A,B

ANL A,#F0h AND the data in A reg with B

SWAP A
Swap the higher and lower nibbles of the A reg.

ADD A,#30h Add the data in A reg with 30.

INC R0 Increment the addr pointed by R0.

MOV @R0,A Copy the data present in A reg to the addr


pointed by R0.
Loop: SJMP Loop
4.Program to convert 8 bit ASCII to its BCD equivalent.

Label Mnemonic Comments

MOV R0,#40h Point reg R0 to the source addr.

MOV A,@R0 Get the data from the addr pointed by R0,

CLR C Clear the carry flag.

SUBB A,#30h Subtract with borrow the data in A reg from 30h.

INC R0 Increment the addr pointed by R0.

MOV @R0,A Copy the data in A reg to the addr pointed by R0.

Loop: SJMP Loop

5. Program to convert 8 bit Binary number to BCD

Label Mnemonic Comments

MOV R0, #30h Load the data 30h to R0

MOV A,@R0 Move the data to A from R0 address

MOV B,#64h Load the data 64h to B

DIV AB Divide A by B

INC R0 Increment R0

MOV @R0,A Copy the data in A to R0 address

MOV A,B Copy the data from B to A

MOV B,#0Ah Load the data 0Ah to B

DIV AB Divide A by B

SWAP A Swap the contents of A

ORL A,B Logical OR A & B

INC R0 Increment R0

MOV @R0,A Load the A data to R0 address

END
6. Program to convert 8 bit BCD to Binary number

Label Mnemonic Comments

MOV A,30h Load the data 30h to A

MOV B,A Copy the contents in A to B

ANL A,#0Fh Logical AND A with 0Fh

MOV R1,A Copy the data in A to R1

MOV A,B Copy the data in in B to A

ANL A,#0F0h Logical AND A with 0F0h

SWAP A Swap the contents of A

MOV B,#0Ah Load the data 0Ah to B

MUL AB Multiply the contents of A with B

ADD A,R1 ADD the data of R1 with A

MOV 31h,A Move the data in A to 31h to A

END

Counter Programming
1. Program to implement 8 bit binary up counter.

Label Mnemonic Comments

MOV R6,#00 Clear the content of reg R6.

Loop: LCALL Delay Call delay Subroutine.

INC R6 Increment the content of R6.

CJNE R6,#00,Loop Compare data in R6 with 00. if not equal loop


back, else stop.
SJMP Loop1

Loop1: MOV R3,#0FFh Move data FF to the reg R3.

Delay: MOV R2,#0FFh Move data FF to reg R2.

Back: DJNZ R2,Here Decrement R2 till it reaches zero.

Here: DJNZ R3,Back Decrement R3 till it reaches zero.

RET
2.Program to implement 8 bit binary down counter.

Label Mnemonic Comments

MOV R6,#0FFh Load the register R6 with FFh..

Loop: LCALL Delay Call delay Subroutine.

DEC R6 Decrement the content of reg R6.

CJNE R6,#0FFh,Loop Compare content of R6 with FF. If not equal

loop back else stop.


SJMP Loop1

Loop1: MOV R3,#0FFh Load R3 with data FFh

Load R2 with data FFh


Delay: MOV R2,#0FFh
Decrement the content of R2 till it reaches zero.
Back: DJNZ R2,Here
Decrement the content of R3, if not zero go back
Here: DJNZ R3,Back
and load R2
RET

3.Program to implement 8 bit BCD up counter.

Label Mnemonic Comments

MOV R6,#00 Clear the contents of register R6.

Loop: LCALL Delay Call delay Subroutine.

MOV A,R6 Get the data in reg R6 to A reg.

ADD A,#01 Add 01 to the content of A reg.

DA A Convert the data in A to its decimal equivalent.

MOV R6,A Copy the data in A regot R6 reg.

CJNE R6,#00,Loop Compare content of R6 with 00. If not equal loop


back. Else stop.
SJMP Loop1
Load R3 with data FFh
MOV R3,#0FFh
Loop1: MOV R2,#0FFh Load R2 with data FFh

Delay: DJNZ R2,Here Decrement the content of R2 till it reaches zero.

Back: DJNZ R3,Back Decrement the content of R3, if not zero go back
and load R2
Here: RET

4. Program to implement 8 bit BCD down counter.

Label Mnemonic Comments

MOV R6,#99h Clear the contents of register R6.

Loop: LCALL Delay Call delay Subroutine.

MOV A,R6 Get the data in reg R6 to A reg.

ADD A,#99h Add 01 to the content of A reg.

DA A Convert the data in A to its decimal equivalent.

MOV R6,A Copy the data in A regot R6 reg.

CJNE R6,#99h,Loop Compare content of R6 with 00. If not equal loop


back. Else stop.
SJMP Loop1

MOV R3,#0FFh Load R3 with data FFh

Loop1: MOV R2,#0FFh Load R2 with data FFh

Delay: DJNZ R2,Here Decrement the content of R2 till it reaches zero.

Back: DJNZ R3,Back Decrement the content of R3, if not zero go back
and load R2
Here: RET
5.Program to implement 8 bit Hex UP counter.

Label Mnemonic Comments

MOV A,#00h Load the data 00h to A

UP: PUSH 0E0h Stack pointes to A to push data

MOV R6,A Get the contents of A to R6

LCALL DELAY Delay function is called

POP 0E0h Stacks points to A to pop data

ADD A,#01H Add 01h to contents of A

CJNE A,#00H,UP Compare and jump to label Up, if A not equal to 0

DELAY: MOV R2,#0Ah Load the count 0Ah to R2

UP1: MOV TMOD,301H Timer 0 and mode 1 is used

MOV TL0,#0FDh Load TL0 with 0FDh

MOV TH0,#4Bh Load TH0 with 04Bh

SETB TR0 Start the timer

CHECK: JNB TF0,CHECK Jump if TF0=0 to check

CLR TR0 Reset the timer value

CLR TF0 Reset the timer flag 0

DJNZ R2,UP1 Decrement and jump to label UP1 if R2 not equal to 0

RET

END

6. Program to implement 8 bit Hex DOWN counter.

Label Mnemonic Comments

MOV A,#0FFh Load the data 00h to A

UP: PUSH 0E0h Stack pointes to A to push data

MOV R6,A Get the contents of A to R6

LCALL DELAY Delay function is called


POP 0E0h Stacks points to A to pop data

CLR C

SUBB A,#01H Subtractwith carry the A data

DELAY: CJNE A,#0FFH,UP Compare and jump to label Up, if A not equal to 0

UP1: MOV R2,#0Ah Load the count 0Ah to R2

MOV TMOD,301H Timer 0 and mode 1 is used

MOV TL0,#0FDh Load TL0 with 0FDh

MOV TH0,#4Bh Load TH0 with 04Bh

CHECK: SETB TR0 Start the timer

JNB TF0,CHECK Jump if TF0=0 to check

CLR TR0 Reset the timer value

CLR TF0 Reset the timer flag 0

DJNZ R2,UP1 Decrement and jump to label UP1 if R2 not equal to 0

RET

END
Instruction set of 8051(nptel.ac.in)

8051 Instructions

8051 has about 111 instructions. These can be grouped into the following categories
1. Arithmetic Instructions
2. Logical Instructions
3. Data Transfer instructions
4. Boolean Variable Instructions
5. Program Branching Instructions

The following nomenclatures for register, data, address and variables are used while write instructions.
A: Accumulator

B: "B" register

C: Carry bit

Rn: Register R0 - R7 of the currently selected register bank

Direct: 8-bit internal direct address for data. The data could be in lower 128bytes of RAM (00 - 7FH) or it could be in the special function
register (80 - FFH).

@Ri: 8-bit external or internal RAM address available in register R0 or R1. This is used for indirect addressing mode.

#data8: Immediate 8-bit data available in the instruction.

#data16: Immediate 16-bit data available in the instruction.

Addr11: 11-bit destination address for short absolute jump. Used by instructions AJMP & ACALL. Jump range is 2 kbyte (one page).

Addr16: 16-bit destination address for long call or long jump.

Rel: 2's complement 8-bit offset (one - byte) used for short jump (SJMP) and all conditional jumps.

bit: Directly addressed bit in internal RAM or SFR


Arithmetic Instructions
Mnemonics Description Bytes Instruction Cycles
ADD A, Rn A A + Rn 1 1
ADD A, direct A A + (direct) 2 1
ADD A, @Ri A A + @Ri 1 1
ADD A, #data A A + data 2 1
ADDC A, Rn A A + Rn + C 1 1
ADDC A, direct A A + (direct) + C 2 1
ADDC A, @Ri A A + @Ri + C 1 1
ADDC A, #data A A + data + C 2 1
DA A Decimal adjust accumulator 1 1
DIV AB Divide A by B
A quotient 1 4
B remainder
DEC A A A -1 1 1
DEC Rn Rn Rn - 1 1 1
DEC direct (direct) (direct) - 1 2 1
DEC @Ri @Ri @Ri - 1 1 1
INC A A A+1 1 1
INC Rn Rn Rn + 1 1 1
INC direct (direct) (direct) + 1 2 1
INC @Ri @Ri @Ri +1 1 1
INC DPTR DPTR DPTR +1 1 2
MUL AB Multiply A by B
A low byte (A*B) 1 4
B high byte (A* B)
SUBB A, Rn A A - Rn - C 1 1
SUBB A, direct A A - (direct) - C 2 1
SUBB A, @Ri A A - @Ri - C 1 1
SUBB A, #data A A - data - C 2 1
Logical Instructions
Mnemonics Description Bytes Instruction Cycles
ANL A, Rn A A AND Rn 1 1
ANL A, direct A A AND (direct) 2 1
ANL A, @Ri A A AND @Ri 1 1
ANL A, #data A A AND data 2 1
ANL direct, A (direct) (direct) AND A 2 1
ANL direct, #data (direct) (direct) AND data 3 2
CLR A A 00H 1 1
CPL A A A 1 1
ORL A, Rn A A OR Rn 1 1
ORL A, direct A A OR (direct) 1 1
ORL A, @Ri A A OR @Ri 2 1
ORL A, #data A A OR data 1 1
ORL direct, A (direct) (direct) OR A 2 1
ORL direct, #data (direct) (direct) OR data 3 2
RL A Rotate accumulator left 1 1
RLC A Rotate accumulator left through carry 1 1
RR A Rotate accumulator right 1 1
RRC A Rotate accumulator right through carry 1 1
SWAP A Swap nibbles within Acumulator 1 1
XRL A, Rn A A EXOR Rn 1 1
XRL A, direct A A EXOR (direct) 1 1
XRL A, @Ri A A EXOR @Ri 2 1
XRL A, #data A A EXOR data 1 1
XRL direct, A (direct) (direct) EXOR A 2 1
XRL direct, #data (direct) (direct) EXOR data 3 2
Data Transfer Instructions
Mnemonics Description Bytes Instruction Cycles
MOV A, Rn A Rn 1 1
MOV A, direct A (direct) 2 1
MOV A, @Ri A @Ri 1 1
MOV A, #data A data 2 1
MOV Rn, A Rn A 1 1
MOV Rn, direct Rn (direct) 2 2
MOV Rn, #data Rn data 2 1
MOV direct, A (direct) A 2 1
MOV direct, Rn (direct) Rn 2 2
MOV direct1, direct2 (direct1) (direct2) 3 2
MOV direct, @Ri (direct) @Ri 2 2
MOV direct, #data (direct) #data 3 2
MOV @Ri, A @Ri A 1 1
MOV @Ri, direct @Ri (direct) 2 2
MOV @Ri, #data @Ri data 2 1
MOV DPTR, #data16 DPTR data16 3 2
MOVC A, @A+DPTR A Code byte pointed by A + DPTR 1 2
MOVC A, @A+PC A Code byte pointed by A + PC 1 2
MOVC A, @Ri A Code byte pointed by Ri 8-bit address) 1 2
MOVX A, @DPTR A External data pointed by DPTR 1 2
MOVX @Ri, A @Ri A (External data - 8bit address) 1 2
MOVX @DPTR, A @DPTR A(External data - 16bit address) 1 2
PUSH direct (SP) (direct) 2 2
POP direct (direct) (SP) 2 2
XCH Rn Exchange A with Rn 1 1
XCH direct Exchange A with direct byte 2 1
XCH @Ri Exchange A with indirect RAM 1 1
XCHD A, @Ri Exchange least significant nibble of A with that of indirect 1 1
RAM
Boolean Variable Instructions
Mnemonics Description Bytes Instruction Cycles
CLR C C-bit 0 1 1
CLR bit bit 0 2 1
SET C C 1 1 1
SET bit bit 1 2 1

CPL C C 1 1
CPL bit bit 2 1

ANL C, /bit C C. 2 1

ANL C, bit C C. bit 2 1

ORL C, /bit C C+ 2 1

ORL C, bit C C + bit 2 1

MOV C, bit C bit 2 1


MOV bit, C bit C 2 2
Program Branching Instructions
Mnemonics Description Bytes Instruction Cycles
ACALL addr11 PC + 2 (SP) ; addr 11 PC 2 2
AJMP addr11 Addr11 PC 2 2
CJNE A, direct, rel Compare with A, jump (PC + rel) if not equal 3 2
CJNE A, #data, rel Compare with A, jump (PC + rel) if not equal 3 2
CJNE Rn, #data, rel Compare with Rn, jump (PC + rel) if not equal 3 2
CJNE @Ri, #data, rel Compare with @Ri A, jump (PC + rel) if not equal 3 2
DJNZ Rn, rel Decrement Rn, jump if not zero 2 2
DJNZ direct, rel Decrement (direct), jump if not zero 3 2
JC rel Jump (PC + rel) if C bit = 1 2 2
JNC rel Jump (PC + rel) if C bit = 0 2 2
JB bit, rel Jump (PC + rel) if bit = 1 3 2
JNB bit, rel Jump (PC + rel) if bit = 0 3 2
JBC bit, rel Jump (PC + rel) if bit = 1 3 2
JMP @A+DPTR A+DPTR PC 1 2
JZ rel If A=0, jump to PC + rel 2 2
JNZ rel If A ≠ 0 , jump to PC + rel 2 2
LCALL addr16 PC + 3 (SP), addr16 PC 3 2
LJMP addr 16 Addr16 PC 3 2
NOP No operation 1 1
RET (SP) PC 1 2
RETI (SP) PC, Enable Interrupt 1 2
SJMP rel PC + 2 + rel PC 2 2
JMP @A+DPTR A+DPTR PC 1 2
JZ rel If A = 0. jump PC+ rel 2 2
JNZ rel If A ≠ 0, jump PC + rel 2 2
NOP No operation 1 1

You might also like