common_banner

Theory - 03: 8051 Microcontroller Instruction Set

Introduction:

Just as our sentences are made of words, a Microcontroller’s (for that matter, any computer) program is made of Instructions. Instructions written in a program tell the Microcontroller which operation to carry out. An Instruction Set is unique to a family of computers.

Writing a Program for any Microcontroller consists of giving commands to the Microcontroller in a particular order in which they must be executed in order to perform a specific task. The commands to the Microcontroller are known as a Microcontroller’s Instruction Set. The instruction set consists of instructions, native data types, addressing modes, interrupt registers, exceptional handling and memory architecture. The 8051 microcontroller can follow CISC instructions with Harvard architecture. This tutorial introduces the 8051 Microcontroller Instruction Set also called as the MCS-51 Instruction Set.

Instruction Set of 8051 Microcontroller

All members of the 8051 family execute the same instructions set. The 8051 instructions set is optimized for 8-bit content application. The Intel 8051 has excellent and most powerful instructions set offers possibilities in control area, serial Input/Output, arithmetic, byte and bit manipulation.

Fig: 8051 All Commands

Before seeing the types of instructions, let us see the structure of the 8051 Microcontroller Instruction.

Fig: A simple 3 byte Instruction structure

An 8051 Instruction consists of an Opcode (short of Operation – Code) followed by Operand(s) of size Zero Byte, One Byte or Two Bytes.

The Op-Code part of the instruction contains the Mnemonic, which specifies the type of operation to be performed. All Mnemonics or the Opcode part of the instruction are of One Byte size.

Coming to the Operand part of the instruction, it defines the data being processed by the instructions. The operand can be any of the following:

  • No Operand
  • Data value
  • I/O Port
  • Memory Location
  • CPU register

8051 series microcontroller has 111 instructions they are:

  • 49 single byte instructions (Only Opcode)
  • 45 two bytes instructions (Opcode + One Byte Operand)
  • 17 three bytes instructions (Opcode + Two Byte Operands)

Based on the operation they perform, all the instructions in the 8051 Microcontroller Instruction Set are divided into five groups. They are:

  • Data Transfer Instructions
  • Arithmetic Instructions
  • Logical Instructions
  • Boolean or Bit Manipulation Instructions
  • Program Branching Instructions

We will now see about these instructions briefly.

Data Transfer Instructions

The Data Transfer Instructions are associated with transfer of data between registers or external program memory or external data memory. The Mnemonics associated with Data Transfer are given below.

  • MOV (Move Data)
  • MOVC (Move Code)
  • MOVX (Move External Data)
  • PUSH (Move Data to Stack)
  • POP (Copy Data from Stack)
  • XCH (Exchange Data between two Registers)
  • XCHD (Exchange Lower Order Data between two Registers)

The following table lists out all the possible data transfer instructions along with other details like addressing mode, size occupied and number machine cycles it takes.

Fig: 8051 Data Transfer operators

Arithmetic Instructions

Using Arithmetic Instructions, you can perform addition, subtraction, multiplication and division. The arithmetic instructions also include increment by one, decrements by one and a special instruction called Decimal Adjust Accumulator. The Mnemonics associated with the Arithmetic Instructions are:

  • ADD (Addition without Carry)
  • ADDC (Addition with Carry)
  • SUBB (Subtract with Carry)
  • INC (Increment by 1)
  • DEC (Decrement by 1)
  • MUL (Multiply)
  • DIV (Divide)
  • DA A (Decimal Adjust the Accumulator (A Register))

All the possible Mnemonics associated with Arithmetic Instructions are mentioned in the following table.

Fig: arithmatic_operator

Note : The arithmetic instructions have no knowledge about the data format i.e., signed, unsigned, ASCII, BCD, etc. Also, the operations performed by the arithmetic instructions affect flags like carry, overflow, zero, etc. in the PSW Register.

Lesson Video

Prev topic: 8051 Architecture Next topic: 8051 Assembly Programming