7.0 Instruction Set Overview
The 8051 features a powerful instruction set optimized for 8-bit control applications. While this specification does not provide a comprehensive opcode list, it categorizes and analyzes the principal groups of instructions related to program flow control and bit-level manipulation.
7.2 Program Flow Control Instructions
These instructions allow a program to deviate from its sequential execution path, enabling loops, conditional logic, and subroutines.
7.2.1 Loop Instructions
The primary instruction for creating loops is DJNZ (Decrement and Jump if Not Zero).
- DJNZ reg, label: This instruction decrements the specified register. If the result is not zero, the program jumps to the specified label. As it operates on an 8-bit register, a single DJNZ instruction is limited to 256 iterations.
7.2.2 Conditional Jumps
Conditional jump instructions test the state of various flags or register bits and alter program flow based on the outcome. All conditional jumps are short jumps, with a relative range of -128 to +127 bytes.
| Instruction | Jump Condition |
| JZ | Jump if Accumulator is Zero |
| JNZ | Jump if Accumulator is Not Zero |
| CJNE | Compare and Jump if Not Equal |
| JC | Jump if Carry Flag is set (CY = 1) |
| JNC | Jump if Carry Flag is not set (CY = 0) |
| JB | Jump if Bit is set (bit = 1) |
| JNB | Jump if Bit is not set (bit = 0) |
| JBC | Jump if Bit is set, then clear the bit |
7.2.3 Unconditional Jumps
These instructions force a jump to a new program address without any conditions.
- LJMP (Long Jump): A 3-byte instruction that can jump to any address within the full 64K program memory space.
- SJMP (Short Jump): A 2-byte instruction that uses a relative offset, limiting its jump range to -128 to +127 bytes from the current location.
7.2.4 Subroutine Call Instructions
These instructions are used to call subroutines, saving the return address on the stack.
- LCALL (Long Call): A 3-byte instruction that can call a subroutine located anywhere in the 64K address space.
- ACALL (Absolute Call): A 2-byte instruction that can call a subroutine located within the same 2K block of memory as the instruction itself.
7.3 Single-Bit Instructions
The 8051 provides a set of instructions that operate on individual bits, a feature extremely useful for control-oriented tasks. These can be used on bit-addressable RAM locations and certain Special Function Registers.
| Instruction | Function |
| SETB | Set the specified bit (bit = 1) |
| CLR | Clear the specified bit (bit = 0) |
| CPL | Complement the specified bit (bit = NOT bit) |
| JB | Jump to target if the specified bit is 1 |
| JNB | Jump to target if the specified bit is 0 |
| JBC | Jump if bit is 1, then clear the bit |
Beyond the core CPU’s instruction set, the 8051’s functionality is significantly extended by its powerful on-chip peripherals.