How to read the tables
Operands: A the accumulator, Rn a register R0-R7 (the opcode’s low three bits), @Ri @R0 or @R1 (the low bit), #d an immediate byte, #d16 a 16-bit immediate (high byte first),
dir a direct address byte, bit a bit address byte, rel a signed displacement from the address of the next instruction, a11 the low eight bits of an AJMP or ACALL address
(bits 10-8 are bits 7-5 of the opcode), a16 a 16-bit address (high byte first). Opcodes are hexadecimal, a range such as E8-EF is one opcode per register. The flags column lists the PSW flags the instruction changes
(CY carry, AC auxiliary carry, OV overflow); the opcode table is the one of the Intel MCS-51 Programmer’s Guide, checked against the Ghidra 8051 definition and the asl assembler.
ACALL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
a11 | 11, 31, 51, 71, 91, B1, D1, F1 | 2 | Call within the 2 KB page of the next instruction |
ADD
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 24 | 2 | CY AC OV | Add an immediate byte to A |
A,dir | 25 | 2 | CY AC OV | Add a direct byte to A |
A,@Ri | 26-27 | 1 | CY AC OV | Add an indirect byte to A |
A,Rn | 28-2F | 1 | CY AC OV | Add a register to A |
ADDC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 34 | 2 | CY AC OV | Add an immediate byte and the carry to A |
A,dir | 35 | 2 | CY AC OV | Add a direct byte and the carry to A |
A,@Ri | 36-37 | 1 | CY AC OV | Add an indirect byte and the carry to A |
A,Rn | 38-3F | 1 | CY AC OV | Add a register and the carry to A |
AJMP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
a11 | 01, 21, 41, 61, 81, A1, C1, E1 | 2 | Jump within the 2 KB page of the next instruction |
ANL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 54 | 2 | AND an immediate byte into A | |
A,dir | 55 | 2 | AND a direct byte into A | |
A,@Ri | 56-57 | 1 | AND an indirect byte into A | |
A,Rn | 58-5F | 1 | AND a register into A | |
dir,A | 52 | 2 | AND A into a direct byte | |
dir,#d | 53 | 3 | AND an immediate byte into a direct byte | |
C,bit | 82 | 2 | CY | AND a bit into the carry |
C,/bit | B0 | 2 | CY | AND the complement of a bit into the carry |
CJNE
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d,rel | B4 | 3 | CY | Compare A with an immediate byte and jump if not equal |
A,dir,rel | B5 | 3 | CY | Compare A with a direct byte and jump if not equal |
@Ri,#d,rel | B6-B7 | 3 | CY | Compare an indirect byte with an immediate byte and jump if not equal |
Rn,#d,rel | B8-BF | 3 | CY | Compare a register with an immediate byte and jump if not equal |
CLR
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | E4 | 1 | Clear A | |
C | C3 | 1 | CY | Clear the carry |
bit | C2 | 2 | Clear a bit |
CPL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | F4 | 1 | Complement A | |
C | B3 | 1 | CY | Complement the carry |
bit | B2 | 2 | Complement a bit |
DA
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | D4 | 1 | CY | Decimal-adjust A after an addition |
DEC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 14 | 1 | Decrement A | |
dir | 15 | 2 | Decrement a direct byte | |
@Ri | 16-17 | 1 | Decrement an indirect byte | |
Rn | 18-1F | 1 | Decrement a register |
DIV
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
AB | 84 | 1 | CY OV | Divide A by B: quotient in A, remainder in B |
DJNZ
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
dir,rel | D5 | 3 | Decrement a direct byte and jump if not zero | |
Rn,rel | D8-DF | 2 | Decrement a register and jump if not zero |
INC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 04 | 1 | Increment A | |
dir | 05 | 2 | Increment a direct byte | |
@Ri | 06-07 | 1 | Increment an indirect byte | |
Rn | 08-0F | 1 | Increment a register | |
DPTR | A3 | 1 | Increment the data pointer |
JB
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
bit,rel | 20 | 3 | Jump if a bit is set |
JBC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
bit,rel | 10 | 3 | Jump if a bit is set, and clear it |
JC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
rel | 40 | 2 | Jump if the carry is set |
JMP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
@A+DPTR | 73 | 1 | Jump to DPTR + A |
JNB
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
bit,rel | 30 | 3 | Jump if a bit is clear |
JNC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
rel | 50 | 2 | Jump if the carry is clear |
JNZ
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
rel | 70 | 2 | Jump if A is not zero |
JZ
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
rel | 60 | 2 | Jump if A is zero |
LCALL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
a16 | 12 | 3 | Call a 16-bit address |
LJMP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
a16 | 02 | 3 | Jump to a 16-bit address |
MOV
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 74 | 2 | Load A with an immediate byte | |
A,dir | E5 | 2 | Copy a direct byte to A | |
A,@Ri | E6-E7 | 1 | Copy an indirect byte to A | |
A,Rn | E8-EF | 1 | Copy a register to A | |
Rn,#d | 78-7F | 2 | Load a register with an immediate byte | |
Rn,dir | A8-AF | 2 | Copy a direct byte to a register | |
Rn,A | F8-FF | 1 | Copy A to a register | |
dir,#d | 75 | 3 | Load a direct byte with an immediate byte | |
dir,dir | 85 | 3 | Copy a direct byte to a direct byte (the first operand byte is the source) | |
dir,@Ri | 86-87 | 2 | Copy an indirect byte to a direct byte | |
dir,Rn | 88-8F | 2 | Copy a register to a direct byte | |
dir,A | F5 | 2 | Copy A to a direct byte | |
@Ri,#d | 76-77 | 2 | Load an indirect byte with an immediate byte | |
@Ri,dir | A6-A7 | 2 | Copy a direct byte to an indirect byte | |
@Ri,A | F6-F7 | 1 | Copy A to an indirect byte | |
DPTR,#d16 | 90 | 3 | Load the data pointer with a 16-bit constant (high byte first) | |
C,bit | A2 | 2 | CY | Copy a bit to the carry |
bit,C | 92 | 2 | Copy the carry to a bit |
MOVC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,@A+PC | 83 | 1 | Load A from code memory at PC + A | |
A,@A+DPTR | 93 | 1 | Load A from code memory at DPTR + A |
MOVX
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,@DPTR | E0 | 1 | Load A from external data memory at DPTR | |
A,@Ri | E2-E3 | 1 | Load A from external data memory at the 8-bit address in Ri | |
@DPTR,A | F0 | 1 | Store A to external data memory at DPTR | |
@Ri,A | F2-F3 | 1 | Store A to external data memory at the 8-bit address in Ri |
MUL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
AB | A4 | 1 | CY OV | Multiply A by B: low byte in A, high byte in B |
NOP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
00 | 1 | No operation |
ORL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 44 | 2 | OR an immediate byte into A | |
A,dir | 45 | 2 | OR a direct byte into A | |
A,@Ri | 46-47 | 1 | OR an indirect byte into A | |
A,Rn | 48-4F | 1 | OR a register into A | |
dir,A | 42 | 2 | OR A into a direct byte | |
dir,#d | 43 | 3 | OR an immediate byte into a direct byte | |
C,bit | 72 | 2 | CY | OR a bit into the carry |
C,/bit | A0 | 2 | CY | OR the complement of a bit into the carry |
POP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
dir | D0 | 2 | Pop the stack into a direct byte |
PUSH
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
dir | C0 | 2 | Push a direct byte on the stack |
RET
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
22 | 1 | Return from a subroutine |
RETI
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
32 | 1 | Return from an interrupt |
RL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 23 | 1 | Rotate A left |
RLC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 33 | 1 | CY | Rotate A left through the carry |
RR
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 03 | 1 | Rotate A right |
RRC
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | 13 | 1 | CY | Rotate A right through the carry |
SETB
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
C | D3 | 1 | CY | Set the carry |
bit | D2 | 2 | Set a bit |
SJMP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
rel | 80 | 2 | Jump to a relative address |
SUBB
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 94 | 2 | CY AC OV | Subtract an immediate byte and the borrow from A |
A,dir | 95 | 2 | CY AC OV | Subtract a direct byte and the borrow from A |
A,@Ri | 96-97 | 1 | CY AC OV | Subtract an indirect byte and the borrow from A |
A,Rn | 98-9F | 1 | CY AC OV | Subtract a register and the borrow from A |
SWAP
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A | C4 | 1 | Swap the nibbles of A |
XCH
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,dir | C5 | 2 | Exchange A with a direct byte | |
A,@Ri | C6-C7 | 1 | Exchange A with an indirect byte | |
A,Rn | C8-CF | 1 | Exchange A with a register |
XCHD
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,@Ri | D6-D7 | 1 | Exchange the low nibbles of A and an indirect byte |
XRL
| Operands | Opcode | Bytes | Flags | What it does |
|---|---|---|---|---|
A,#d | 64 | 2 | Exclusive-OR an immediate byte into A | |
A,dir | 65 | 2 | Exclusive-OR a direct byte into A | |
A,@Ri | 66-67 | 1 | Exclusive-OR an indirect byte into A | |
A,Rn | 68-6F | 1 | Exclusive-OR a register into A | |
dir,A | 62 | 2 | Exclusive-OR A into a direct byte | |
dir,#d | 63 | 3 | Exclusive-OR an immediate byte into a direct byte |
Not described
Known, not yet covered
- Reference: the cycle count of each instruction, the exact operation of
DA,MUL,DIV(carry and overflow rules) and of the PSW parity flag.