0% found this document useful (0 votes)
48 views14 pages

Addressing Modes of 8051

The 8051 CPU can access data using several addressing modes: 1. Immediate addressing uses a constant as the operand and loads data directly into registers like MOV A,#25H. 2. Register addressing moves data between registers of the same size like MOV R4,R5. 3. Direct addressing directly accesses RAM locations 30-7FH like MOV R0,30H. 4. Register indirect addressing uses registers R0-R1 to hold memory addresses accessed with @R0 like MOV A,@R0. 5. Indexed addressing adds the contents of register A to DPTR to access lookup tables like MOVC A,@A+DPTR.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views14 pages

Addressing Modes of 8051

The 8051 CPU can access data using several addressing modes: 1. Immediate addressing uses a constant as the operand and loads data directly into registers like MOV A,#25H. 2. Register addressing moves data between registers of the same size like MOV R4,R5. 3. Direct addressing directly accesses RAM locations 30-7FH like MOV R0,30H. 4. Register indirect addressing uses registers R0-R1 to hold memory addresses accessed with @R0 like MOV A,@R0. 5. Indexed addressing adds the contents of register A to DPTR to access lookup tables like MOVC A,@A+DPTR.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Addressing modes of 8051

The CPU can access data in various


ways, which are called addressing

modes
Immediate
Register
Direct
Register indirect
Indexed

Immediate addressing mode


The source operand is a constant
The immediate data must be
preceded by the pound sign, #
Can load information into any
registers, including 16-bit DPTR
register DPTR can also be accessed
as two 8-bit registers, the high byte
DPH and low byte DPL

MOV A,#25H ;load 25H into A


MOV R4,#62 ;load 62 into R4
MOV B,#40H ;load 40H into B
MOV DPTR,#4521H ;DPTR=4512H
MOV DPL,#21H ;This is the same
MOV DPH,#45H ;as above; illegal!!
Value > 65535 (FFFFH)
MOV DPTR,#68975

We can use EQU directive to access


immediate data
Count EQU 30
... ...
MOV R4,#COUNT ;R4=1EH
MOV DPTR,#MYDATA ;DPTR=200H
ORG 200H
MYDATA: DB INDIA
We can also use immediate addressing
mode to
MOV P1,#55H send data to 8051 ports

Register addressing mode


Use registers to hold the data to be
manipulated
The source and destination registers
must match in size
MOV DPTR, A will give an error
The movement of data between Rn
registers is not allowed

Direct addressing mode


It is most often used the direct
addressing mode to access RAM
locations 30 7FH
The entire 128 bytes of RAM can be
accessed
The register bank locations are
accessed by the register name
Contrast this with immediate
addressing mode
There is no # sign in the operand

The SFR (Special Function Register) can be


accessed by their names or by their addresses
MOV 0E0H,#55H ;
is the same as
MOV A,#55h ;
load 55H into A
MOV 0F0H,R0 ;
is the same as
MOV B,R0 ;
copy R0 into B
The SFR registers have addresses between
80H and FFH
Not all the address space of 80 to FF is used
by SFR
The unused locations 80H to FFH are reserved
and must not be used by the 8051
programmer

Stack and Direct addressing mode


Only direct addressing mode is allowed for pushing
or popping the stack
PUSH A is invalid
Pushing the accumulator onto the stack must be
coded as PUSH 0E0H
PUSH 05
PUSH 0E0H
POP 0F0H
POP 02

;push R5 onto stack


;push register A onto stack
;pop top of stack into B
;now register B = register A
;pop top of stack into R2
;now R2=R6s PUSH 0E0H

Register Addressing mode


A register is used as a pointer to the data
Only register R0 and R1 are used for this
purpose
R2 R7 cannot be used to hold the
address of an operand located in RAM
When R0 and R1 hold the addresses of
RAM locations, they must be preceded by
the @ sign

MOV A,@R0 ;move contents of RAM whose


;address is held by R0 into A
MOV @R1, B ;move contents of B into RAM
;whose address is held by R1
The advantage is that it makes accessing
data dynamic rather than static as in direct
addressing mode
Looping is not possible in direct addressing
mode

R0 and R1 are the only registers that can be


used for pointers in register indirect
addressing mode
Since R0 and R1 are 8 bits wide, their use is
limited to access any information in the
internal RAM
Whether accessing externally connected
RAM or on-chip ROM, we need 16-bit pointer
In such case, the DPTR register is used

Indexed addressing mode


Indexed addressing mode is widely used in
accessing data elements of look-up table
entries located in the
program ROM
The instruction used for this purpose is
MOVC A,@A+DPTR
Use instruction MOVC, C means code
The contents of A are added to the 16-bit
register DPTR to form the 16-bit address of the
needed data

You might also like