Addressing Modes of 8051 Microcontroller
The length of an 8051 instruction is 1, 2, or 3 bytes. The
opcode for an instruction is always 8 bits long. Hence 28 256
opcodes are possible, of which 255 opcodes have been
implemented. They can be classified into 111 types of
instructions. If the crystal frequency is 12 MHz, then 64
instruction types are executed in just 1s, and the rest in just 2s
(except for multiply and divide instructions that need 4s). Intel
8051 provides the following addressing modes for accessing
data from internal data memory or external data memory
The CPU can access data in various ways.
The data could be in a register, or in memory, or be
provided as an immediate value.
These various ways of accessing data are called addressing
modes.
The 8051 provides distinct addressing modes. They are as
follows: 1)Register Addressing
2)Register Indirect Addressing
3)Direct Byte Addressing
4)Stack Addressing
5)Register-Specific/ Implied Addressing
6)Immediate Addressing
7)Base + Index Register Addressing
Register Addressing
It involves the use of registers to hold the data to be
manipulated.
Register Indirect Addressing
In this mode, a register is used as a pointer to the data. If
the data is inside the CPU, only registers R0 and R1 are used for
this purpose
When R0 and R1 are used as pointers, that is, when they hold
the addresses of RAM locations, they must be preceded by the
“@” sign
Examples
MOV A, @R1
Direct Byte Addressing
There are 128 bytes of RAM in the 8051. The RAM has
been assigned addresses 00 to 7FH. In the direct addressing
mode, the data is in a RAM location whose address is known,
and this address is given as a part of the instruction.
MOV A, 33H
MOV 32, R1
Stack and Direct Addressing
Another major use of direct addressing mode is the stack.
In the 8051 family, only direct addressing mode is allowed for
pushing onto the stack. (PUSH instruction)
Direct addressing mode must be used for the POP
instruction as well
Examples:
Register Specific/Implied Addressing
Inherent in the instruction, these refer to a specific
register such as an accumulator (A) or DPTR
SWAP A
RL A
RR A
CPL A
Immediate Addressing
In this addressing mode, the source operand is a constant.
In immediate addressing mode, as the name implies, when the
instruction is assembled, the operand comes immediately after
the opcode.
Notice that the immediate data must be preceded by the
pound sign, “#”.
Base + Index Register Addressing
Indexed addressing mode is widely used in accessing data
elements of look-up table entries located in the program ROM
space of the 8051. The instruction used for this purpose is
“MOVC A,@A+DPTR”. The 16-bit register DPTR and register A
are used to form the address of the data element stored in the
on-chip ROM In this instruction the contents of A are added to
the 16-bit register DPTR to form the 16-bit address of the
needed data
Examples:
MOVC A,@A+PC : Move a byte of data from program
memory, whose address can be determined by the sum of the
accumulator and program counter, to the accumulator.
MOVC A,@A+DPTR: Move a byte of data from program
memory, whose address can be found by adding the
accumulator and the data pointer, to the accumulator
Examples:
MOVC A, @A+DPTR
Where, A – Index Register, DPTR- Base Register,
C- Code/Program memory