1.2 INSTRUCTION SET OF 8051

  • Data Transfer Instructions
  • Arithmetic Instructions
  • Logical Instructions
  • Branch Instructions
  • Bit Manipulation Instructions

1.2.1 DATA TRANSFER INSTRUCTIONS

Data transfer instructions move the content of one register to another. The register the content of which is moved remains unchanged. If they have the suffix “X” (MOVX), the data is exchanged with external memory.

MnemonicDescriptionByteCycle
MOV A, RnMoves the content of register to the accumulator11
MOV A, directMoves the content of direct address to the accumulator22
MOV A, @RiMoves the content of address in Ri to the accumulator12
MOV A, #dataMoves the immediate data to the accumulator22
MOV Rn, AMoves the content of accumulator to the register12
MOV Rn, directMoves the content of direct address to the register24
MOV Rn, #dataMoves the immediate data to the register22
MOV direct, AMoves the content of accumulator to the direct address23
MOV @Ri, AMoves the accumulator to the indirect RAM13
MOV @Ri, directMoves the direct byte to the indirect RAM25
MOV @Ri, #dataMoves the immediate data to the indirect RAM23
MOV DPTR, #dataMoves a 16-bit data to the data pointer33
MOVC A, @A+DPTRMoves the code byte relative to the DPTR to the accumulator (address=A+DPTR)13
MOVX A, @RiMoves the external RAM (8-bit address) to the accumulator13-10
MOVX A, @DPTRMoves the content of external RAM (16-bit address) to the accumulator13-10
MOVX @Ri, AMoves the content of accumulator to the external RAM (8-bit address)14-11
MOVX @DPTR, AMoves the content of accumulator to the external RAM (16-bit address)14-11
PUSH directPushes the direct byte onto the stack23
POP directPops the direct byte from the stack23
XCH A, RnExchanges the register with the accumulator11
XCH A, directExchanges the direct byte with the accumulator22
XCH A, @RiExchanges the indirect RAM with the accumulator12
XCHD A, @RiExchanges the low-order nibble indirect RAM with the accumulator12

1.2.2 ARITHMETIC INSTRUCTIONS

Arithmetic instructions perform several basic operations such as addition, subtraction, division, multiplication etc. After execution, the result is stored in the first operand. For example: ADD A, R1 – The result of addition (A+R1) will be stored in the accumulator.

MnemonicDescriptionByteCycle
ADD A, RnAdds the register to the accumulator11
ADD A, directAdds the direct byte to the accumulator22
ADD A, @RiAdds the indirect RAM to the accumulator12
ADD A, #dataAdds the immediate data to the accumulator22
ADDC A, RnAdds the register to the accumulator with a carry flag11
ADDC A, directAdds the direct byte to the accumulator with a carry flag22
ADDC A, @RiAdds the indirect RAM to the accumulator with a carry flag12
ADDC A, #dataAdds the immediate data to the accumulator with a carry flag22
SUBB A, RnSubtracts the register from the accumulator with a borrow11
SUBB A, directSubtracts the direct byte from the accumulator with a borrow22
SUBB A, @RiSubtracts the indirect RAM from the accumulator with a borrow12
SUBB A, #dataSubtracts the immediate data from the accumulator with a borrow22
INC AIncrements the accumulator by 111
INC RnIncrements the register by 111
INC directIncrements the direct byte by 123
INC @RiIncrements the indirect RAM by 113
DEC ADecrements the accumulator by 111
DEC RnDecrements the register by 111
DEC directDecrements the direct byte by 123
DEC @RiDecrements the indirect RAM by 113
INC DPTRIncrements the Data Pointer by 111
MUL ABMultiplies A and B14
DIV ABDivides A by B14
DA ADecimal adjustment of the accumulator according to BCD code11

1.2.3 LOGICAL INSTRUCTIONS

Logical instructions perform logic operations upon corresponding bits of two registers. After execution, the result is stored in the first operand.

MnemonicDescriptionByteCycle
ANL A, RnAND register to accumulator11
ANL A, directAND direct byte to accumulator22
ANL A, @RiAND indirect RAM to accumulator12
ANL A, #dataAND immediate data to accumulator22
ANL direct, AAND accumulator to direct byte23
ANL direct, #dataAND immediate data to direct register34
ORL A, RnOR register to accumulator11
ORL A, directOR direct byte to accumulator22
ORL A, @RiOR indirect RAM to accumulator12
ORL direct, AOR accumulator to direct byte23
ORL direct, #dataOR immediate data to direct byte34
XRL A, RnExclusive OR register to accumulator11
XRL A, directExclusive OR direct byte to accumulator22
XRL A, @RiExclusive OR indirect RAM to accumulator12
XRL A, #dataExclusive OR immediate data to accumulator22
XRL direct, AExclusive OR accumulator to direct byte23
XRL direct, #dataExclusive OR immediate data to direct byte34
CLR AClears the accumulator11
CPL AComplements the accumulator (1=0, 0=1)11
SWAP ASwaps nibbles within the accumulator11
RL ARotates bits in the accumulator left11
RLC ARotates bits in the accumulator left through carry11
RR ARotates bits in the accumulator right11
RRC ARotates bits in the accumulator right through carry11

1.2.4 BRANCH INSTRUCTIONS

There are two kinds of branch instructions:

  • Unconditional jump instructions: upon their execution a jump to a new location from where the program continues execution is executed.
  • Conditional jump instructions: a jump to a new program location is executed only if a specified condition is met. Otherwise, the program normally proceeds with the next instruction.
MnemonicDescriptionByteCycle
ACALL addr11Absolute subroutine call26
LCALL addr16Long subroutine call36
RETReturns from subroutine14
RETIReturns from interrupt subroutine14
AJMP addr11Absolute jump23
LJMP addr16Long jump34
SJMP relShort jump (from -128 to +127 locations relative to the following instruction)23
JC relJump if carry flag is set. Short jump.23
JNC relJump if carry flag is not set. Short jump.23
JB bit, relJump if direct bit is set. Short jump.34
JBC bit, relJump if direct bit is set and clears bit. Short jump.34
JMP @A+DPTRJump indirect relative to the DPTR12
JZ relJump if the accumulator is zero. Short jump.23
JNZ relJump if the accumulator is not zero. Short jump.23
CJNE A, direct, relCompares direct byte to the accumulator and jumps if not equal. Short jump.34
CJNE A, #data, relCompares immediate data to the accumulator and jumps if not equal. Short jump.34
CJNE Rn, #data, relCompares immediate data to the register and jumps if not equal. Short jump.34
CJNE @Ri, #data, relCompares immediate data to indirect register and jumps if not equal. Short jump.34
DJNZ Rn, relDecrements register and jumps if not 0. Short jump.23
DJNZ direct, relDecrements direct byte and jump if not 0. Short jump.34
NOPNo operation1

1.2.5 BIT MANIPULATION INSTRUCTIONS

Similar to logic instructions, bit manipulation instructions perform logic operations. The difference is that these are performed upon single bits.

MnemonicDescriptionByteCycle
CLR CClears the carry flag11
CLR bitClears the direct bit23
SETB CSets the carry flag11
SETB bitSets the direct bit23
CPL CComplements the carry flag11
CPL bitComplements the direct bit23
ANL C, bitAND direct bit to the carry flag22
ANL C, /bitAND complements of direct bit to the carry flag22
ORL C, bitOR direct bit to the carry flag22
ORL C, /bitOR complements of direct bit to the carry flag22
MOV C, bitMoves the direct bit to the carry flag22
MOV bit, CMoves the carry flag to the direct bit23

Leave a Comment