8051 Instrunctions
8051 Instrunctions
UNIT-2
2.1 8051 INSTRUCTION SET
Mnemonic Description Byte
ARITHMETIC OPERATIONS
ADD A,Rn Add register to Accumulator 1
ADD A,direct Add direct byte to Accumulator 2
ADD A,@Ri Add indirect RAM to Accumulator 1
ADD A,#data Add immediate data to Accumulator 2
ADDC A,Rn Add register to Accumulator with Carry 1
ADDC A,direct Add direct byte to Accumulator with Carry 2
ADDC A,@Ri Add indirect RAM to Accumulator with Carry 1
ADDC A,#data Add immediate data to Accumulator with Carry 2
SUBB A,Rn Subtract Register from Acc with Borrow 1
SUBB A,direct Subtract direct byte from Acc with Borrow 2
SUBB A,@Ri Subtract indirect RAM from Acc with Borrow 1
SUBB A,#data Subtract immediate data from Acc with Borrow 2
INC A Increment Accumulator 1
INC Rn Increment Register 1
INC direct Increment direct byte 2
INC @Ri Increment indirect RAM 1
DEC A Decrement Accumulator 1
DEC Rn Decrement Register 1
DEC direct Decrement direct byte 2
DEC @Ri Decrement indirect RAM 1
INC DPTR Increment Data Pointer 1
MUL AB Multiply A and B 1
DIV AB Divide A by B 1
DA A Decimal Adjust Accumulator 1
Mnemonic Description Byte
LOGICAL OPERATIONS
ANL A,Rn AND Register to Accumulator 1
ANL A,direct AND direct byte to Accumulator 2
ANL A,@Ri AND indirect RAM to Accumulator 1
ANL A,#data AND immediate data to Accumulator 2
ANL direct,A AND Accumulator to direct byte 2
ANL direct,#data AND immediate data to direct byte 3
ORL A,Rn OR Register to Accumulator 1
ORL A,direct OR direct byte to Accumulator 2
ORL A,@Ri OR indirect RAM to Accumulator 1
ORL A,#data OR immediate data to Accumulator 2
ORL direct,A OR Accumulator to direct byte 2
ORL direct,#data OR immediate data to direct byte 3
XRL A,Rn Exclusive-OR Register to Accumulator 1
XRL A,direct Exclusive-OR direct byte to Accumulator 2
XRL A,@Ri Exclusive-OR indirect RAM to Accumulator 1
XRL A,#data Exclusive-OR immediate data to Acc 2
XRL direct,A Exclusive-OR Accumulator to direct byte 2
XRL direct,#data Exclusive-OR immediate data to direct byte 3
CLR A Clear Accumulator 1
CPL A Complement Accumulator 1
RL A Rotate Accumulator Left 1
RLC A Rotate Accumulator Left through Carry 1
RR A Rotate Accumulator Right 1
RRC A Rotate Accumulator Right through the Carry 1
SWAP A Swap nibbles within the Accumulator 1
Mnemonic Description Byte
DATA TRANSFER
MOV A,Rn Move Register to Accumulator 1
MOV A,direct Move direct byte to Accumulator 2
MOV A,@Ri Move indirect RAM to Accumulator 1
MOV A,#data Move immediate data to Accumulator 2
MOV Rn,A Move Accumulator to register 1
MOV Rn,direct Move direct byte to register 2
MOV Rn,#data Move immediate data to register 2
MOV direct,A Move Accumulator to direct byte 2
MOV direct,Rn Move register to direct byte 2
MOV direct,direct Move direct byte to direct 3
MOV direct,@Ri Move indirect RAM to direct byte 2
MOV direct,#data Move immediate data to direct byte 3
MOV @Ri,A Move Accumulator to indirect RAM 1
MOV @Ri,direct Move direct byte to indirect RAM 2
MOV @Ri,#data Move immediate data to indirect RAM 2
MOV DPTR,#data16 Load Data Pointer with a 16-bit constant 3
MOVC A,@A+DPTR Move Code byte relative to DPTR to Acc 1
MOVC A,@A+PC Move Code byte relative to PC to Acc 1
MOVX A,@Ri Move external RAM(8-bit address) to Acc 1
MOVX A,@DPTR Move external RAM(16-bit address) to Acc 1
MOVX @Ri,A Move Acc to external RAM(8-bit address) 1
MOVX @DPTR,A Move Acc to external RAM(16-bit address) 1
PUSH direct Push direct byte onto stack 2
POP direct Pop direct byte from stack 2
XCH A,Rn Exchange Register with Accumulator 1
XCH A,direct Exchange direct byte with Accumulator 2
XCH A,@Ri Exchange indirect RAM with Accumulator 1
A,@Ri Exchange low order Digit indirect RAM
XCHD 1
with Accumulator
Mnemonic Description Byte
BOOLEAN VARIABLE MANIPULATION
CLR C Clear Carry 1
CLR bit Clear direct bit 2
SETB C Set Carry 1
SETB bit Set direct bit 2
CPL C Complement Carry 1
CPL bit Complement direct bit 2
ANL C,bit AND direct bit to CARRY 2
ANL C,/bit AND complement of direct bit to Carry 2
ORL C,bit OR direct bit to Carry 2
ORL C,/bit OR complement of direct bit to Carry 2
MOV C,bit Move direct bit to Carry 2
MOV bit,C Move Carry to direct bit 2
JC rel Jump if Carry is set 2
JNC rel Jump if Carry not set 2
JB bit,rel Jump if direct Bit is set 3
JNB bit,rel Jump if direct Bit is Not set 3
JBC bit,rel Jump if direct Bit is set & clear bit 3
Mnemonic Description Byte
PROGRAM BRANCHING
ACALL addr11 Absolute Subroutine Call 2
LCALL addr16 Long Subroutine Call 3
RET Return from Subroutine 1
RETI Return from interrupt 1
AJMP addr11 Absolute Jump 2
LJMP addr16 Long Jump 3
SJMP rel Short Jump (relative addr) 2
JMP @A+DPTR Jump indirect relative to the DPTR 1
JZ rel Jump if Accumulator is Zero 2
JNZ rel Jump if Accumulator is Not Zero 2
Compare direct byte to Acc and Jump if
CJNE A,direct,rel 3
Not Equal
Compare immediate to Acc and Jump if
CJNE A,#data,rel 3
Not Equal
Compare immediate to register and Jump if
CJNE Rn,#data,rel 3
Not Equal
Compare immediate to indirect and Jump if
CJNE @Ri,#data,rel 3
Not Equal
DJNZ Rn,rel Decrement register and Jump if Not Zero 2
Decrement direct byte and Jump if Not
DJNZ direct,rel 3
Zero
NOP No Operation 1
2.2 8051 ADDRESSING MODES
What is an addressing mode ?
Addressing mode is a way to address an operand.
Operand means the data we are operating upon (in most cases source data). It can be
a direct address of memory, it can be register names, it can be any numerical data etc.
For example,
MOV A,#2AH
Here, Operand= 2A
On execution of this instruction, the data 2AH is moved to accumulator A.
There are five different ways of executing this instruction. Thus, we can say that there
are 5 addressing modes of 8051.
Types of Addressing Modes in 8051
1. Immediate addressing mode
2. Direct addressing mode
3. Register direct addressing mode
4. Register indirect addressing mode
5. Indexed addressing mode.
Prepared by
Shweta Sharma