Instruction Set in 8051 Microcontroller
Instruction Set in 8051 Microcontroller
Table of Contents
1. Instructions in ALP
2. Instruction Set in 8051 Microcontroller Family
2.1. Arithmetic instructions
2.2. Branch Instructions
2.3. Data Transfer Instructions
2.4. Logical Instructions
2.5. Bit-oriented Instructions
3. Recent posts
3.1. How to Read a Capacitor
3.2. How to Read a Capacitor
3.3. Variable Capacitor
3.4. Variable Capacitor
3.5. Electrolytic Capacitor
3.6. Related posts:
Depending on operation they perform, instruction set in 8051 microcontroller is divided in several groups, such as:
Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions
Instructions in ALP
The first part of each instruction, called MNEMONIC refers to the operation an instruction performs (copy, addition,
logic operation etc.). Mnemonics are abbreviations of the name of operation being executed.
For example:
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 1/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
The other part of instruction, called OPERAND is separated from mnemonic by at least one whitespace and defines
Ads by
data being processed by instructions.
Stop seeing this ad Why this ad?
Some of the instructions have no operand, while some of them have one, two or three. If there is more than one
operand in an instruction, they are separated by a comma.
For example:
A – accumulator;
Rn – is one of working registers (R0-R7) in the currently active RAM memory bank;
Direct – is any 8-bit address register of RAM. It can be any general-purpose register or a SFR (I/O port, control
register etc.);
@Ri – is indirect internal or external RAM location addressed by register R0 or R1;
#data – is an 8-bit constant included in instruction (0-255);
#data16 – is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
addr16 – is a 16-bit address. May be anywhere within 64KB of program memory;
addr11 – is an 11-bit address. May be within the same 2KB page of program memory as the first byte of the
following instruction;
rel – is the address of a close memory location (from -128 to +127 relative to the first byte of the following
instruction). On the basis of it, assembler computes the value to add or subtract from the number currently stored in
the program counter;
bit – is any bit-addressable I/O pin, control or status bit; and
C – is carry flag of the status register (register PSW).
Arithmetic Instructions
Arithmetic instructions perform several basic operations such as addition, subtraction, division, multiplication etc.
After execution, the result is stored in the first operand.
Arithmetic Instructions
ADDC A,Rn Adds the register to the accumulator with a carry flag 1 1
ADDC A,direct Adds the direct byte to the accumulator with a carry flag 2 2
ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag 1 2
ADDC A,#data Adds the immediate data to the accumulator with a carry flag 2 2
SUBB A,Rn Subtracts the register from the accumulator with a borrow 1 1
SUBB A,direct Subtracts the direct byte from the accumulator with a borrow 2 2
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 2/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow 1 2
SUBB A,#data Subtracts the immediate data from the accumulator with a borrow 2 2
DIV AB Divides A by B 1 5
Branch Instructions
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where the program continues
execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a specified condition is met.
Otherwise, the program normally proceeds with the next instruction.
Branch Instructions
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 3/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
JBC bit,rel Jump if direct bit is set and clears bit. Short jump. 3 4
Compares direct byte to the accumulator and jumps if not equal. Short
CJNE A,direct,rel 3 4
jump.
Compares immediate data to the accumulator and jumps if not equal. Short
CJNE A,#data,rel 3 4
jump.
Compares immediate data to the register and jumps if not equal. Short
CJNE Rn,#data,rel 3 4
jump.
CJNE Compares immediate data to indirect register and jumps if not equal. Short
3 4
@Ri,#data,rel jump.
DJNZ Direct,rel Decrements direct byte and jump if not 0. Short jump. 3 4
NOP No operation 1 1
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 4/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
MOVC Moves the code byte relative to the DPTR to the accumulator
1 3
A,@A+DPTR (address=A+DPTR)
MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator (address=A+PC) 1 3
MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator 1 3-10
MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator 1 3-10
MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address) 1 4-11
MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address) 1 4-11
XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the accumulator 1 3
Logical Instructions
Logic instructions perform logic operations upon corresponding bits of two registers. After execution, the result is
stored in the first operand.
Logic Instructions
ANL
AND immediae data to direct register 3 4
direct,#data
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 5/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
ORL
OR immediate data to direct byte 3 4
direct,#data
XORL
Exclusive OR immediate data to direct byte 3 4
direct,#data
Bit-Oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that these are
performed upon single bits.
Bit-oriented Instructions
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 6/10
23/11/2023, 19:23 Instruction Set in 8051 Microcontroller
Recent posts
Related Posts:
1. Assembler Directives in 8051 Microcontroller
2. Features of 8051 Microcontroller
3. Memory Organization of 8051 Microcontroller
4. Addressing Modes in 8051 Microcontroller
5. Architecture of 8051 Microcontroller
6. PSW Register in 8051 Microcontroller | Program Status Word
7. Pin Configuration of 8051 Microcontroller
8. The Stack and Stack Pointer in 8051 Microcontroller
9. Stack Pointer Data Pointer and Program Counter in 8051 Microcontroller
10. Functions of Timing and Control Unit of 8051
11. Functions of Ports in 8051 Microcontroller
12. Port Structure of 8051 Microcontroller
13. Reset Circuit of 8051 Microcontroller
14. Registers in 8051 Microcontroller
15. Boolean Processor in 8051 Microcontroller
16. Power Saving Mode in 8051 | 8051 Power Down and Idle Mode
17. 8051 Microcontroller Family
18. Program Development Steps in ALP
RUSSIAN
01/11/2023 AT 3:42 PM
https://electronicsforyou.in/instruction-set-in-8051-microcontroller/ 7/10