Module 4 - Lecture 5
Module 4 - Lecture 5
Lecture 5
Contents: 2
The different ways in which a source operand in an instruction are known as the
addressing modes.
Addressing modes
In immediate addressing mode, when the instruction is assembled, the operand comes
immediately after the op-code.
This addressing mode can be used to load information into any of the register, including the
DPTR.
Example:
MOV A, #25H // load 25H into A
MOV R4, #62 // load the decimal value 62 into R4.
MOV B, #40H // load 40H into B
MOV DPTR, #4532H // DPTR=4532H.
Immediate addressing mode:
6
DPTR can also be accessed as two 8-bit registers.
Example:
MOV DPTR, #2550H // is the same as:
MOV DPL, #50H
MOV DPH, #25H
MOV DPTR, #68975 // illegal !! Value > 65535 (FFFFFH)
We can also use immediate addressing mode to send data to 8051 ports
Example:
Example:
MOV DPTR, A // will give an error
Contrast this with the immediate addressing mode in which the operand itself is provided
with the instruction (there is no “#” sign in the operand).
Example:
MOV R0, 40H // save content of RAM location 40H into R0.
MOV R4, 7FH // move content of RAM location 7FH into R4.
Direct addressing mode:
10
The register bank locations are accessed by
Example:
MOV A, 4 // is same as
MOV A, 7 // is same as
MOV A, 2 // is same as
MOV A, 0 // is same as
The SFR (Special Function Register) can be accessed by their names or by their addresses.
The unused locations 80H to FFH are reserved and must not be used by the 8051
programmer.
SFR registers and their addresses:
12
Example: MOV 0E0H, #55H // is the same as
Solution:
(a)
MOV A, #55H // A=55H
PUSH A is invalid
Pushing the accumulator onto the stack must be coded as PUSH 0E0H
Example: Show the code to push R5 and A onto the stack and pop them into R2 and B, where
B=A and R2=R5.
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.
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
Register indirect addressing mode:
18
Example: Write a program to copy the value 55H into RAM memory locations 40H to 44H using
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.
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.
Indexed addressing mode:
22
Example: In this program, assume that the word “USA” is burned into ROM locations starting
at 200H, and that the program is burned into ROM locations starting at 0. Analyze how the
program works and state where “USA” is stored after this program is run.