Instruction Set of 8051 Microcontroller

The 8051 instruction set is divided into 4 functional groups,

  1. Arithmetic:  

Addition:

  • ADD – 8-bit addition between the accumulator (A) and a second operand. The result is always in the accumulator. The CY flag is set/reset appropriately.
  • ADDC (Add with carry) – 8-bit addition between the accumulator, a second operand and the previous value of the CY flag puts the result in A
  • DA – Decimal adjust the accumulator, Format the accumulator into a proper 2 digit packed BCD number. Operates only on the accumulator. Works only after the ADD instruction.

Substraction:

  • SUBB – Subtract with Borrow. Subtract an operand and the previous value of the borrow (carry) flag from the accumulator. 
  • DEC – Decrement the operand by one from the source operand and returns the result to the operand.

Multiplication: MUL performs the multiplication of the A register by the B register, returning a double byte result. MUL AB– Multiply A by B and place result in A

Division: DIV AB divides the unsigned eight-bit integer in the Accumulator by the unsigned eight-bit integer in register B. The Accumulator receives the integer part of the quotient; register B receives the integer remainder. The carry and OV flags are cleared.

2. Logic:  

Logical operations in 8051 perform bitwise operations between the accumulator and data stored in a memory location, register, or data given by the programmer. The result of a logical operation is stored in the accumulator itself.

  • ANL – can be used to clear (0) certain bits
  • ORL – can be used to set (1) certain bits 
  • CLR A – All bits in register A are cleared
  • CPL A  – All bits in register A are complemented (inverted) ,Note that CLR and CPL instructions operate on register A 
  • RL A – Rotates A one bit position to the left
  • RLC A – Rotates A and the carry flag one bit position to the left
  • RR A – Rotates A one bit position to the right
  •  RRC A – Rotates A and the carry flag one bit position to the right 

3)Data Transfer:  

  • MOV – Performs a bit or byte transfer from the source operand to the destination operand.
  • PUSH / POP – Push and Pop a data byte onto the stack. The data byte is identified by a direct address from the internal RAM locations.
  • XCH: Exchanges the value of the Accumulator with the value contained in register. e.g. XCH A, R0 – exchanges the value between A and R0
  • XCHD (Exchange Digit) – Exchange lower digit of accumulator with the lower digit of the memory location specified. XCHD A, @Ri

4)Control Transfer: There are 3 classes of operations.

  • Unconditional calls, returns & jumps
  • Conditional Jumps
  • Interrupt returns

Unconditional Jump: Transfer control unconditionally to a new address.

  •  LJMP 16 bit address – LJMP is used to jump to any address location within 64KB code memory space of the 8051.
  • SJMP (Short jump) –  This is a 2 –byte instruction the first byte is opcode and the second byte is a singed number displacement, which is added with the PC of the instruction following the SJMP to get the target address.
  • AJMP (Absolute jump) –   It transfer the program execution to the target address unconditionally the target address for this instruction must be with in 2K byte memory.

You may also like...

error: Content is protected !!