Appendix E - 8051 Instruction Set

Mnemonic Description Size Cycles
ADD A,Rn  Add register to Accumulator (ACC). 1 1
ADD A,direct  Add direct byte to ACC. 2 1
ADD A,@Ri  Add indirect RAM to ACC. 1 1
ADD A,#data  Add immediate data to ACC. 2 1
ADDC A,Rn  Add register to ACC with carry. 1 1
ADDC A,direct  Add direct byte to ACC with carry. 2 1
ADDC A,@Ri  Add indirect RAM to ACC with carry. 1 1
ADDC A,#data  Add immediate data to ACC with carry. 2 1
SUBB A,Rn  Subtract register from ACC with borrow. 1 1
SUBB A,direct  Subtract direct byte from ACC with borrow 2 1
SUBB A,@Ri  Subtract indirect RAM from ACC with borrow. 1 1
SUBB A,#data  Subtract immediate data from ACC with borrow. 2 1
INC A  Increment ACC. 1 1
INC Rn  Increment register. 1 1
INC direct  Increment direct byte. 2 1
INC @Ri  Increment indirect RAM. 1 1
DEC A  Decrement ACC. 1 1
DEC Rn  Decrement register. 1 1
DEC direct  Decrement direct byte. 2 1
DEC @Ri  Decrement indirect RAM. 1 1
INC DPTR  Increment data pointer. 1 2
MUL AB  Multiply A and B Result: A <- low byte, B <- high byte. 1 4
DIV AB  Divide A by B Result: A <- whole part, B <- remainder.  1 4
DA A  Decimal adjust ACC. 1 1
Logical Operations

Mnemonic Description Size Cycles
ANL A,Rn  AND Register to ACC. 1 1
ANL A,direct  AND direct byte to ACC. 2 1
ANL A,@Ri  AND indirect RAM to ACC. 1 1
ANL A,#data  AND immediate data to ACC. 2 1
ANL direct,A  AND ACC to direct byte. 2 1
ANL direct,#data  AND immediate data to direct byte. 3 2
ORL A,Rn  OR Register to ACC. 1 1
ORL A,direct  OR direct byte to ACC. 2 1
ORL A,@Ri  OR indirect RAM to ACC. 1 1
ORL A,#data  OR immediate data to ACC. 2 1
ORL direct,A  OR ACC to direct byte. 2 1
ORL direct,#data  OR immediate data to direct byte. 3 2
XRL A,Rn  Exclusive OR Register to ACC. 1 1
XRL A,direct  Exclusive OR direct byte to ACC. 2 1
XRL A,@Ri  Exclusive OR indirect RAM to ACC. 1 1
XRL A,#data  Exclusive OR immediate data to ACC. 2 1
XRL direct,A  Exclusive OR ACC to direct byte. 2 1
XRL direct,#data  XOR immediate data to direct byte. 3 2
CLR A  Clear ACC (set all bits to zero). 1 1
CPL A  Compliment ACC. 1 1
RL A  Rotate ACC left. 1 1
RLC A  Rotate ACC left through carry. 1 1
RR A  Rotate ACC right. 1 1
RRC A  Rotate ACC right through carry. 1 1
SWAP A  Swap nibbles within ACC. 1 1
Data Transfer

Mnemonic Description Size Cycles
MOV A,Rn  Move register to ACC. 1 1
MOV A,direct  Move direct byte to ACC. 2 1
MOV A,@Ri  Move indirect RAM to ACC. 1 1
MOV A,#data  Move immediate data to ACC. 2 1
MOV Rn,A  Move ACC to register. 1 1
MOV Rn,direct  Move direct byte to register. 2 2
MOV Rn,#data  Move immediate data to register. 2 1
MOV direct,A  Move ACC to direct byte. 2 1
MOV direct,Rn  Move register to direct byte. 2 2
MOV direct,direct  Move direct byte to direct byte. 3 2
MOV direct,@Ri  Move indirect RAM to direct byte. 2 2
MOV direct,#data  Move immediate data to direct byte. 3 2
MOV @Ri,A  Move ACC to indirect RAM. 1 1
MOV @Ri,direct  Move direct byte to indirect RAM. 2 2
MOV @Ri,#data  Move immediate data to indirect RAM. 2 1
MOV DPTR,#data16  Move immediate 16 bit data to data pointer register. 3 2
MOVC A,@A+DPTR  Move code byte relative to DPTR to ACC (16 bit address). 1 2
MOVC A,@A+PC  Move code byte relative to PC to ACC (16 bit address). 1 2
MOVX A,@Ri  Move external RAM to ACC (8 bit address). 1 2
MOVX A,@DPTR  Move external RAM to ACC (16 bit address). 1 2
MOVX @Ri,A  Move ACC to external RAM (8 bit address). 1 2
MOVX @DPTR,A  Move ACC to external RAM (16 bit address). 1 2
PUSH direct  Push direct byte onto stack. 2 2
POP direct  Pop direct byte from stack. 2 2
XCH A,Rn  Exchange register with ACC. 1 1
XCH A,direct  Exchange direct byte with ACC. 2 1
XCH A,@Ri  Exchange indirect RAM with ACC. 1 1
XCHD A,@Ri  Exchange low order nibble of indirect RAM with low order nibble of ACC. 1 1
Boolean Variable Manipulation

Mnemonic Description Size Cycles
CLR C  Clear carry flag. 1 1
CLR bit  Clear direct bit. 2 1
SETB C  Set carry flag. 1 1
SETB bit  Set direct bit. 2 1
CPL C  Compliment carry flag. 1 1
CPL bit  Compliment direct bit. 2 1
ANL C,bit  AND direct bit to carry flag. 2 2
ANL C,/bit  AND compliment of direct bit to carry. 2 2
ORL C,bit  OR direct bit to carry flag. 2 2
ORL C,/bit  OR compliment of direct bit to carry. 2 2
MOV C,bit  Move direct bit to carry flag. 2 1
MOV bit,C  Move carry to direct bit. 2 2
JC rel  Jump if carry is set. 2 2
JNC rel  Jump if carry is not set. 2 2
JB bit,rel  Jump if direct bit is set. 3 2
JNB bit,rel  Jump if direct bit is not set. 3 2
JBC bit,rel  Jump if direct bit is set & clear bit. 3 2
Program Branching

Mnemonic Description Size Cycles
ACALL addr11  Absolute subroutine call. 2 2
LCALL addr16  Long subroutine call. 3 2
RET  Return from subroutine. 1 2
RETI  Return from interrupt. 1 2
AJMP addr11  Absolute jump. 2 2
LJMP addr16  Long jump. 3 2
SJMP rel  Short jump (relative address). 2 2
JMP @A+DPTR  Jump indirect relative to the DPTR. 1 2
JZ rel  Jump relative if ACC is zero. 2 2
JNZ rel  Jump relative if ACC is not zero. 2 2
CJNE A,direct,rel  Compare direct byte to ACC and jump if not equal. 3 2
CJNE A,#data,rel  Compare immediate byte to ACC and jump if not equal. 3 2
CJNE Rn,#data,rel  Compare immediate byte to register and jump if not equal. 3 2
CJNE @Ri,#data,rel  Compare immediate byte to indirect and jump if not equal. 3 2
DJNZ Rn,rel  Decrement register and jump if not zero. 2 2
DJNZ direct,rel  Decrement direct byte and jump if not zero. 3 2
Other Instructions

Mnemonic Description Size Cycles
NOP  No operation. 1 1


关于在 KEIL C51 中直接嵌入汇编

有时在C51程序中需要嵌入一些汇编代码,这时当然可以用通常的作法:
按 照 C51 与汇编的接口写一个汇编函数,然后在 C51 程序中调用该函数。(此种方法可在论坛里搜索,以前有很多帖子讲到,不再
重复)

下 面介绍直接嵌入汇编代码的方法:

1、在 C 文件中要嵌入汇编代码片以如下方式加入汇编代码:
#pragma ASM
; Assembler Code Here
#pragma ENDASM

2、在 Project 窗口中包含汇编代码的 C 文件上右键,选择“Options for ...”,点击右边的“Generate Assembler SRC File”
和“Assemble SRC File”,使检查框由灰色变成黑色(有效)状态;

3、根据选择的编译模式,把相应的库文件(如 Small 模式时,是 KeilC51LibC51S.Lib)加入工程中, 该文件必须作为工程的最
后文件;

4、编译,即可生成目标代码。