11.4.3 Indirect Addressing
Indirect Addressing allows the user to access a location in data memory without giving a fixed address in the instruction. This is done by using File Select Registers (FSRs) as pointers to the locations which are to be read or written. Since the FSRs are themselves located in RAM as Special File Registers, they can also be directly manipulated under program control. This makes FSRs very useful in implementing data structures, such as tables and arrays in data memory.
The registers for Indirect Addressing are also implemented with Indirect File Operands (INDFs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. This allows for efficient code, using loops, such as the following example of clearing an entire RAM bank.
How to Clear RAM (Bank 1) Using Indirect Addressing
LFSR FSR0,100h ; Set FSR0 to beginning of Bank1
NEXT:
CLRF POSTINC0 ; Clear location in Bank1 then increment FSR0
BTFSS FSR0H,1 ; Has high FSR0 byte incremented to next bank?
BRA NEXT ; NO, clear next byte in Bank1
CONTINUE: ; YES, continue