The document discusses different addressing modes in 8051 microcontrollers. It describes 5 addressing modes: immediate, register, direct, register indirect, and indexed. Immediate addressing uses data included in the instruction. Register addressing uses register names to specify operands. Direct addressing directly specifies the memory location address. Register indirect addressing uses a register pointer to an address. Indexed addressing combines the contents of two registers, like PC and accumulator, to form the address.
1. Addressing Modes in 8051
Microcontroller
A.Usha Rani,
Department of Physics and Electronics,
St.Ann’s College for Women
2. Basics of a program statement in
assembly language
A statement in assembly language program consists of
three
fields-
Label
Instructions
Comments
These fields are arranged as
[Label:] Instructions [//Comments]
Label
It is used to assign name to the memory location or
program
3. Instructions
Every instruction has two parts
Opcode - It specifies the operation to be performed.
Operands – It is the data on which operation is to be
performed
Operands are of two types.
Source operand – The operands which are inputs for an
operation.
Destination operand – The operands that will store the
result of an operation.
4. Comments
Comments are used to describe the operation performed
by an instruction.
They help in understanding the program easily.
Mostly comments start with “//”
Example
MOV R0, #10H //Move 10H into register R0
Opcode – MOV
Operands – R0, 10H
6. The various ways of accessing data are called
addressing modes.
The way by which the source and destination
operands are specified in an instruction are
called addressing modes.
The instruction may contain one or more
operands.
These addressing modes are determined when
it is designed and cannot be changed by the
Programmer.
7. 8051 microcontroller provides five addressing
modes.
Immediate
Register
Direct
Register Indirect Addressing
Indexed Addressing
8. Immediate Addressing Mode
The operand comes immediately after the opcode
The data is given as part of the instruction.
The immediate data must be preceded by the sign
‘#’
The source operand is constant.
The information can be loaded into any of the
registers including DPTR
9. MOV A, #data // Load the immediate data
into A
MOV Rn, # data // Load the immediate data in to
Rn
MOV DPTR, # data // Load the data into DPTR
Examples
MOV A,# 25H // Load the value 25H into A
MOV R, #63H //Load 63H into register R
MOV DPTR, #4521H // Load 4251H into the
10. Register Addressing Mode
The operands are specified by register names.
It requires only one byte memory.
Involves the use of registers to hold the data to be
manipulated.
11. MOV A, Rn //Copy the contents of register Rn to
A
MOV Rn, A //Copy the contents of A into register
Rn
Examples
MOV A,R1 //Copy the contents of register R1 into
A
MOV R2, A // Copy the contents of A into the
register R2
12. Direct Addressing Mode
The data is stored in RAM memory location
whose address is known and the address is given as
part of the instruction.
The data is accessed directly from the memory.
13. MOV A, Direct // Copy data from address Direct into A
MOV Direct, A //Copy data from A into address
Direct
MOV Rn, Direct //Copy data from address
Direct into register Rn
MOV Direct, Rn // Copy data from register Rn into
address Direct
MOV Direct, #data // load immediate data into
address Direct
MOV direct1,direct2 //copy data from address direct2
14. Examples
MOV A, 10H //Copy data from address 10H into A
MOV 10H, A //Copy data from A into address 10H
MOV R5, 80H //Copy data from address 80H into
register R5
MOV 50H, R3 // Copy data from register R3 into
address 50H
MOV 20H, #32H // load immediate data 32H into
address 20H
MOV 62H,83H //copy data from address 83H
to address 62H
15. Register Indirect Addressing Mode
A register is used a pointer to the data.
Only the registers R0 and R1 can be used to hold
the address of the data in internal RAM.
These registers are called pointer registers.
When registers are used as pointers they are
preceded by the sign’@’
16. MOV A, @Ri //Copy data from address in Ri to
A
MOV @Ri, A //Copy data from A into address in
Ri
MOV Direct, @Ri //Copy data from address in
Ri to address Direct
MOV @Ri, Direct //Copy data from address
direct to address Ri
MOV @Ri, #data // Load the immediate value
data into address in Ri
17. Examples
MOV A, @R1 //Copy data from address in R1 to
A
MOV @R0, A //Copy data from A into address in
R0
MOV Direct, @R0 //Copy data from address in R0 to
address Direct
MOV @R1, Direct //Copy data from address direct to
address R1
MOV @R1, #data //Load the immediate value data
18. Indexed Addressing Mode
Two registers are used to form the address of
the data.
The contents of either Program Counter(PC) or
Data Pointer(DPTR) are used as base address and
Accumulator is used as index address.
The combination of the contents of these two
registers gives the final address.
This addressing mode is used to access data
tables from program memory and in
implementing jump tables
19. MOVC A,@A+PC // copy data from
program memory address
formed by addition of
contents of A and PC into A
MOVC A,@A+DPTR // copy data from
program memory
address formed by
addition of contents of A and
DPTR into A