Addressing Modes of 8051
Addressing Modes
The CPU can access data various ways The data could be in a register, or memory or as an immediate value
The various ways of accessing data are called addressing modes.
Types of addressing mode
- Direct addressing mode
- Indirect addressing mode
- Register addressing
- Register specific addressing (optional)
- Immediate addressing
- External Addressing ( Index )
- Code access
- Data access
Direct addressing mode
- In this mode the operand is specified by an 8-bit address field In the instruction.
- One can access all the 128 bytes of internal RAM locations and each SFR.
- If the MSB bit = 0 then the location is within on chip internal RAM. If MSB bit = 1 then the location is SFR.
- The location 00h to 7Fh to address the internal RAM .
- SFR addresses from 80h to FF H
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOV | A, | 40H | ;Load the contents of RAM location 40H into A |
Example:-
- MOV R1, 45H ;Move the contents of RAM location 45 into R1 register
- MOV 47H,A ;Move the contents of the accumulator into the RAM location 47h.
- ADD A, 43H ;Add the contents of the RAM location 43H to the accumulator
Indirect Addressing Mode
In this addressing mode, the instruction specifics a register which contains address of an operand i.e. the register hold the actual address that will be used in the data move operation.
- The R0 and R1 of each bank can be used as an index or pointer to memory location
- The sign @ indicates the register acts as a pointer to memory locations
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOV | A, | @Ri | ;Load the contents of Memory location pointed by Ri register into A |
Example:-
- MOV A,@ R0 :Move the contents of RAM location whose address is pointed to by R0 into A (accumulator)
- MOV @ R1 , B : Move the contents of B into RAM location whose address is pointed to by R1
Register Addressing
- Each bank consist of register R0 to R7 can be used as general purpose register for selection of bank register, the user has to modify the two bits of PSW
- These register can be used to stored the address or data in the register addressing mode
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOV | A, | R7 | ;Load the contents of R7 register into A |
Example:-
- MOV A,R0 ;Move or load the contents of the register R0 to the accumulator
- ADD A,R6 ;Add the contents of R6 register to the accumulator
- MOV P1, R2 ;Move the contents of the R2 register into port 1
- MOV R5, R2 ;This is invalid .The data transfer between the registers is not allowed.
Note: MOV R3,R5 is an invalid instruction
Register specific Addressing Mode
In this addressing mode the instruction refer to a specific registers such as accumulator or data pointer
Example :-
- DA A ; Decimal adjust accumulator
- SWAP A ; Swap lower nibble with Higher nibble
Immediate Addressing Mode
- This method is the simplest method to get the data.
- In this addressing mode the source operand is a constant rather then a variable.
- As the data source is a part of instruction
- The # sign indicates that the data followed is immediate operand.
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOV | A, | #30H | ;Load the immediate value 30H into A |
Example:-MOV A,#30h
MOV P1,#0FF
MOV DPTR, #1234h
External addressing modeor Indexed addressing mode
Code access (ROM access)
- Using these instructions only program memory can be accessed.
- This addressing mode is preferred for reading look up tables in the program memory.
- Either DPTR or PC can be used as pointer.
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOVC | A, | @A+DPTR | ;Load the immediate value present at memory location pointed to by @A+DPTR in A |
Example:-
- MOVC A,@A+DPTR ;Load the immediate value present at memory location pointed to by @A+DPTR in A
- MOVC A,@A+PC ;Load the immediate value present at memory location pointed to by @A+PC in A
Data access (RAM access)
- Using this addressing mode the programmer can access the external Data memory
Syntax | Mnemonics | Destination Operand | Source Operand | Comment |
MOVX | A, | @A+DPTR | ;Load the immediate value present at memory location pointed to by @A+DPTR in A |
Example:-
- MOVX A,@DPTR ;Load the immediate value present at memory location pointed to by @DPTR in A
- MOVX @R0,A ;Load the immediate value present in A into memory location pointed to by @R0
References
- WikiNote Foundation