3.1.3 Register Indirect Addressing

Register Indirect Addressing is used to access any location in data memory by treating the contents of a Working register as an Effective Address (EA) to data memory. Essentially, the contents of the Working register become a pointer to the location in data memory that is to be accessed by the instruction.

This addressing mode is powerful because it also allows one to modify the contents of the Working register, either before or after the data access is made, by incrementing or decrementing the EA. By modifying the EA in the same cycle that an operation is being performed, Register Indirect Addressing allows for the efficient processing of data that is stored sequentially in memory. The modes of Indirect Addressing supported by PIC32A devices are shown in Table 3-2.

Table 3-2. Indirect Addressing Modes
Indirect ModeSyntaxFunction

(Byte Instruction)

Function

(Word Instruction)

Function (Long word instruction)Description
No Modification[Wn]EA = [Wn]EA = [Wn]EA = [Wn]The contents of Wn form the EA.
Pre-Increment[++Wn]EA = [Wn + = 1]EA = [Wn + = 2]EA = [Wn + = 4]Wn is pre-incremented to form the EA.
Pre-Decrement[--Wn]EA = [Wn – = 1]EA = [Wn – = 2]EA = [Wn – = 4]Wn is pre-decremented to form the EA.
Post-Increment[Wn++]EA = [Wn]+ = 1EA = [Wn]+ = 2EA = [Wn]+ = 4The contents of Wn form the EA, then Wn is post-incremented.
Post-Decrement[Wn--]EA = [Wn] – = 1EA = [Wn] – = 2EA = [Wn] – = 4The contents of Wn form the EA, then Wn is post-decremented.
Register Offset[Wn+Wb]EA = [Wn + Wb]EA = [Wn + Wb]EA = [Wn + Wb]The sum of Wn and Wb forms the EA. Wn and Wb are not modified.

Table 3-2 shows that four addressing modes modify the EA used in the instruction, and this allows the following updates to be made to the Working register: post-increment, post-decrement, pre-increment and pre-decrement.

Table 3-2 also shows that the Register Offset mode addresses data which is offset from a base EA stored in a Working register. This mode uses the contents of a second Working register to form the EA by adding the two specified Working registers. Note that neither of the Working registers used to form the EA is modified. Indirect Addressing with Effective Address Update shows how Register Offset Indirect Addressing may be used to access data memory.

Note: The MOV with offset instructions provides a literal addressing offset ability to be used with Indirect Addressing. In these instructions, the EA is formed by adding the contents of a Working register to a signed literal. Indirect Addressing with Register Offset shows how these instructions may be used to move data to and from the Working register array.

Indirect Addressing with Effective Address Update

MOV.B		[W0++], [W13--]				; byte move [W0] to [W13]
; post-inc W0, post-dec W13

Before Instruction:

W0 = 0x2300
W13 = 0x2708
Data Memory 0x2300 = 0x7783
Data Memory 0x2708 = 0x904E

After Instruction:

W0 = 0x2301
W13 = 0x2707
Data Memory 0x2300 = 0x7783
Data Memory 0x2708 = 0x9083
ADD		W1, [--W5], [++W8]	; pre-dec W5, pre-inc W8
; add W1 to [W5], store in [W8]

Before Instruction:

W1 = 0x0800
W5 = 0x2200
W8 = 0x2400
Data Memory 0x21FE = 0x7783
Data Memory 0x2402 = 0xAACC

After Instruction:

W1 = 0x0800
W5 = 0x21FE
W8 = 0x2402
Data Memory 0x21FE = 0x7783
Data Memory 0x2402 = 0x7F83

Indirect Addressing with Register Offset

MOV.B		[W0+W1], [W7++]	; byte move 
;[W0+W1] to W7, post-inc W7

Before Instruction:

W0 = 0x2300
W1 = 0x01FE
W7 = 0x1000
Data Memory 0x24FE = 0x7783
Data Memory 0x1000 = 0x11DC

After Instruction:

W0 = 0x2300
W1 = 0x01FE
W7 = 0x1001
Data Memory 0x24FE = 0x7783
Data Memory 0x1000 = 0x1183
LAC.l		[W0+W8], A	   ; load ACCA with [W0+W8]
                                         ; (sign-extend and zero-backfill)

Before Instruction:

W0 = 0x2344
W8 = 0x0008
ACCA = 0x00 7877 9321 0000 0000
Data Memory 0x234C = 0xE290

After Instruction:

W0 = 0x2344
W8 = 0x0008
ACCA = 0xFF E290 0000 0000 0000
Data Memory 0x234C = 0xE290

Move with Literal Offset Instructions

MOV		[W0+0x20], W1		 ; move [W0+0x20] to W1

Before Instruction:

W0 = 0x1200
W1 = 0x01FE
Data Memory 0x1220 = 0xFD27

After Instruction:

W0 = 0x1200
W1 = 0xFD27
Data Memory 0x1220 = 0xFD27
MOV		W4, [W8-0x300]		; move W4 to [W8-0x300]

Before Instruction:

W4 = 0x3411
W8 = 0x2944
Data Memory 0x2644 = 0xCB98

After Instruction:

W4 = 0x3411
W8 = 0x2944
Data Memory 0x2644 = 0x3411