Indirect Addressing Mode

Indirect Addressing Mode

For all the addressing modes covered to this point, the source or destination of the data is an absolute number or a name. Inspection of the opcode reveals exactly what are the addresses of the destination and source. For example, the opcode MOV A,R7 says that the A regis­ter will get a copy of whatever data is in register R7; MOV 33h,#32h moves the hex number 32 to hex RAM address 33.
The indirect addressing mode uses a register to hold the actual address that will finally be used in the data move; the register itself is not the address, but rather the number in the register. Indirect addressing for MOV opcodes uses register R0 or R1, often called “data pointers,” to hold the address of one of the data locations, which could be a RAM or an SFR address. The number that is in the pointing register (Rp) cannot be known un­less the history of the register is known. The mnemonic symbol used for indirect address­ing is the “at” sign, which is printed as @.
The moves made possible using immediate, direct, register and indirect addressing modes are as follows:
Mnemonic Operation
MOV @ Rp, #n Copy the immediate byte n to the address in Rp
MOV @Rp,add Copy the contents of add to the address in Rp
MOV @Rp ,A Copy the data in A to the address in Rp
MOV add,@ Rp Copy the contents of the address in Rp to add
MOV A,@ Rp Copy the contents of the address in Rp to A
The following table shows examples of MOV opcodes, using immediate, register, direct, and indirect modes
Mnemonic Operation
MOV A,@R0 Copy the contents of the address in R0to the A register
MOV @R1,#35h Copy the number 35h to the address in R 1
MOV add,@R0 Copy the contents of the address in R0 to add
MOV @R1,A Copy the contents of A to the address in R 1
MOV @R0,80h Copy the contents of the port 0 pins to the address in R0

CAUTION

The number in register Rp must be a RAM or an SFR address. Only registers R0 or R1 may be used for indirect addressing. 

External Data Moves

As discussed in Chapter 2. it is possible to expand RAM and ROM memory space by adding external memory chips to the 8051 microcontroller. The external memory can be as large as 64K bytes for each of the RAM and ROM memory areas. Opcodes that access this external memory always use indirect addressing to specify the external memory.
Figure 3.2 shows that registers R0. R1. and the aptly named DPTR can be used to hold the address of the data byte in external RAM. R0 and R1 are limited to external RAM address ranges of 00h to 0FFh. while the DPTR register can address the maxi­mum RAM space of 0000h to 0FFFFh.
An X is added to the MOV mnemonics to serve as a reminder that the data move is external to the 8051. As shown in the following table.
Mnemonic Operation
MOVX A.@Rp Copy the contents of the external address in Rp to A
MOVX A.@DPTR Copy the contents of the external address in DPTR to A
MOVX @Rp.A Copy data from A to the external address in Rp
MOVX @DPTR.A Copy data from A to the external address in DPTR
The following table shows examples of external moves using register and indirect addressing modes:
Mnemonic Operation
MOVX @DPTR.A Copy data from A to the 16-bit address in DPTR
MOVX @R0,A Copy data from A to the 8-bit address in R0
MOVX A,@R1 Copy data from the 8-bit address in R 1 to A
MOVX A,@DPTR Copy data from the 16-bit address in DPTR to A

CAUTION

All external data moves must involve the A register.
Rp can address 256 bytes; DPTR can address 64K bytes.
MOVX is normally used with external RAM or I/O addresses.
Note that there are two sets of RAM addresses between 00 and 0FFh: one internal and one external to the 8051.

Leave a comment

Your email address will not be published. Required fields are marked *