ADDRESSING
MODES OF 8051
DEFINITION
• The CPU can access the data in various ways.
• The data could be in a register, or in memory or
be provided as an immediate value.
• The method of specifying the data to be operated
by the instruction is called addressing.
• The different ways that a microprocessor can
access data are referred to as addressing modes.
CLASSIFICATION
• There are 5 addressing modes supported by
8051 microcontroller.
1.Immediate
2.Register
3.Direct
4. Register indirect
5. Indexed
IMMEDIATE ADDRESSING
• In this addressing mode the source operand is
constant.
• In immediate addressing mode, when the instruction is
assembled, the operand comes immediately after the
op-code.
• The immediate data must be preceded by ‘#’ sign.
• This addressing mode can be used to load information
into any of the register, including the DPTR.
EXAMPLE…
•MOV A,#25H - Load 25H in to A
•MOV R4,#62 - Load the decimal value 62
into R4.
• MOV DPTR,#4532H – Load DPTR=4532H
• MOV DPH,#45H
• MOV DPL,#32H
CONTINUE…
• This addressing mode can be used to send
data to 8051 ports.
• MOV P1, #55 H
REGISTER ADDRESSING
• Register addressing mode involves the use
of registers to hold the data to be
manipulated.
• In this addressing, registers (R0 to R7 from
the selected register bank), accumulator, B-
register and DPTR are used.
CONTINUE…
• The source and destination registers should
be of same size.
• The data can be moved from A register to Rn
register. But movement of data between Rn
registers are not allowed.
EXAMPLE…
• MOV A,R0 - copy the contents of R0 in to A.
• MOV R2,A - copy the contents of A in to R2.
• ADD A,R5 - add the content of R5 to content of
A.
• MOV R7,DPL - copy the contents of DPL in to
R7.
• MOV R4,R3 – Invalid instruction.
DIRECT ADDRESSING
• In direct addressing mode, the data is in a RAM
memory location whose address is known, and this
address is given as a part of the instruction.
• Contrast this with the immediate addressing mode in
which the operand itself is provided with the
instruction.
• The sign “#” distinguishes between the two
addressing modes.
CONTINUE…
• This addressing mode is limited to accessing RAM
locations (00 – FF H) and registers located inside the
8051.
• Only direct addressing mode is allowed for pushing
onto the stack.
• Therefore an instruction ‘PUSH A’ is invalid.
• Pushing the accumulator onto the stack must be coded
as ‘PUSH 0E0 H’. (Address of A register is 0E0)
EXAMPLE…
• MOV R0,40H - save content of RAM location 40h
into R0.
• MOV 56H,A - save content of A in RAM location
56H.
• MOV A, 02 – is same as
MOV A,R2 – which means copy R2 into A
REGISTER INDIRECT ADDRESSING
• In the register indirect addressing mode, a register
is used as a pointer to the data.
• If the data is inside the CPU, only register R0 and
R1 are used for this purpose.
• In other words,R2-R7 cannot be used to hold the
address of an operand located in RAM when using
this addressing mode.
CONTINUE…
• When R0 and R1 are used as pointers , that is, when
they hold the address of RAM locations , they must
be preceded by the “@” sign.
• The advantage of using this addressing mode is that,
it makes accessing data dynamic rather than static as
in the case of direct addressing mode.
• The registers R0 and R1 usage is limited to accessing
any information in the internal RAM.(30 H – 7F H)
EXAMPLE…
• MOV A,@R0 - move contents of RAM
location whose address is held by R0 into A.
• MOV @R1,B - move contents of B
RAM location whose address is held by R1
INDEXED 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”.
CONTINUE…
• The 16-bit register DPTR and register “A”
are used to form the data element stored in
on-chip ROM.
• Because the data elements are stored in the
program space ROM of the 8051,it uses the
instruction MOVC instead of MOV.
• The “C” means code.
EXAMPLE…
• “MOVC A, @A+DPTR”
• In this instruction the content of A are added
to the 16-bit register DPTR to form the 16-bit
address of the needed data.