8051 Instruction Set: Opcode, Operand, Size, and M-Cycle

8051
instruction set
microcontroller
opcode
machine cycle

This page covers the 8051 instruction set, detailing the opcode, operand, size in bytes, and M-cycle (number of machine cycles) for each instruction. Remember that one machine cycle consists of 12 oscillator periods.

Table 1 explains the terms used in the instruction tables, along with their addressing modes.

Table 1: Instruction Terminology

InstructionsDescription
RnRegister R7 to R0.
direct8-bit address of the internal data location.
@Ri8-bit address of internal RAM indicated by register R1 or R0.
#data8-bit constant included in the instruction.
#data1616-bit constant included in the instruction.
addr1616-bit destination address.
addr1111-bit destination address.
relSigned (2’s complement) 8-bit offset byte.
bitDirect addressed bit in internal data RAM or SFR (Special Function Register).

8051 Instruction Set Categories

The 8051 instruction set is divided into the following categories:

  • Arithmetic instructions
  • Logical instructions
  • Data transfer instructions
  • Boolean instructions
  • Branching instructions

Arithmetic Instructions

InstructionOpcodeOperandSize (Bytes)Machine CyclesDescription
ADD A,Rn11Add register to accumulator
ADDC A,Rn11Add register to accumulator with carry
SUBB A,Rn11Subtract register from ACC with borrow
INC A11Increment accumulator
DEC A11Decrement accumulator
INC DPTR12Increment data pointer
MUL AB14Multiply A and B (48 Oscillator periods)
DIV AB14Divide A by B (Oscillator periods)

Logical Instructions

InstructionOpcodeOperandSize (Bytes)Machine CyclesDescription
ANL A,Rn11AND register to Accumulator
ANL A,direct21AND direct byte to accumulator
ANL A,@Ri11AND indirect RAM to accumulator
ANL A,#data21AND immediate data to accumulator
ANL direct,A21AND accumulator to direct byte
ANL direct,#data32AND immediate data to direct byte
ORL A,Rn11OR register to accumulator
XRL A,Rn11Exclusive-OR register to accumulator
CLR A11Clear accumulator
CPL A11Complement accumulator
RL A11Rotate accumulator left
RLC A11Rotate accumulator left through the carry
RR A11Rotate accumulator right
RRC A11Rotate accumulator right through the carry
SWAP A11Swap nibbles within the accumulator

Data Transfer Instructions

InstructionOpcodeOperandSize (Bytes)Machine CyclesDescription
MOV A,Rn11Move register to accumulator
MOV A,direct21Move direct byte to accumulator
MOV A,#data21Move immediate data to accumulator
MOVC A,@A+DPTR12Move code byte relative to DPTR to Acc
MOVX A,@Ri12Move external RAM (8-bit address) to Acc.
PUSH direct22Push direct byte onto stack
POP direct22POP direct byte from stack
XCH A,Rn11Exchange register with accumulator
XCH A,direct21Exchange direct byte with accumulator
XCH A,@Ri11Exchange indirect RAM with accumulator
XCHD A,@Ri11Exchange low order digit of indirect RAM with ACC

Boolean Instructions

InstructionOpcodeOperandSize (Bytes)Machine CyclesDescription
CLR C11Clear Carry
CLR bit21Clear direct bit
SETB C11Set carry
SETB bit21Set direct bit
CPL C11Complement carry
CPL bit21Complement direct bit
ANL C,bit22AND direct bit to carry
ANL C,/bit22AND complement of direct bit to carry
ORL C,bit22OR direct bit to carry
MOV C,bit21Move direct bit to carry
MOV bit,C22Move carry to direct bit
JC rel22Jump if carry is set
JNC rel22Jump if carry is not set
JB bit,rel32Jump if direct bit is set
JNB bit,rel32Jump if direct bit is not set
JBC bit,rel32Jump if direct bit is set and clear bit

Branching Instructions

InstructionOpcodeOperandSize (Bytes)Machine CyclesDescription
ACALL addr1122Absolute subroutine call
LCALL addr1632Long subrouting call
RET12Return from subroutine
RETI12Return from interrupt
AJMP addr1122Absolute Jump
LJMP addr1632Long Jump
JMP @A+DPTR12Jump indirect relative to the DPTR
JZ rel22Jump if accumulator is zero
JNZ rel22Jump if accumulator is non-zero
CJNE A,direct,rel32Compare direct byte to acc and jump if not equal
DJNZ Rn,rel22Decrement register and jump if not zero
DJNZ direct,rel32Decrement direct byte and jump if not zero
NOP11No Operation (12 oscillator periods implied, but listed as 1 cycle)
Intel 8051 Microcontroller Architecture Explained

Intel 8051 Microcontroller Architecture Explained

Explore the Intel 8051 microcontroller architecture, covering its key components like CPU, memory, I/O ports, timers, serial communication, and interrupts. Learn about its practical applications.

microcontroller
8051
embedded systems