4.8.1.1 Table Read/Write Instructions

The tblpage() and tbloffset() operators provided by the assembler can be used with table read/write instructions. These operators may be applied to any symbol (usually representing a table of constant data) in program memory.

Suppose a table of constant data is declared in program memory like this:

.text
fib_data:
.word 0, 1, 2, 3, 5, 8, 13

To access this table with table read/write instructions, use the tblpage() and tbloffset() operators as follows:

; Set TBLPAG to the page that contains the fib_data array.
mov		#tblpage(fib_data), w0
mov		w0, _TBLPAG
; Make a pointer to fib_data for table instructions
mov		#tbloffset(fib_data), w0
; Load the first data value
tblrdl		[w0++], w1

The programmer must ensure that the constant data table does not exceed the program memory page size that is implied by the TBLPAG register. The maximum table size implied by the TBLPAG register is 64 Kbytes. If additional constant data storage is required, simply create additional tables each with its own symbol, and repeat the code sequence above to load the TBLPAG register and derive a pointer.