11.2.1 Table Access Instructions
The table access instructions tblrdl
,
tblrdh
, tblwtl
and
tblwth
can be used to access data stored in program
memory. Data is addressed through a 16-bit data register pointer in combination with the
8-bit TBLPAG register. The special operators tbloffset()
and tblpage()
facilitate table access in assembly
language. See the MPLAB XC-DSC assembler documentation, 4.8.1.1 Table Read/Write Instructions, for more
information.
The linker resolves symbolic references to labels in program memory for use with the table access instructions. Although data in program memory can be specified one byte at a time, only the least-significant byte in each instruction word has a unique address. For example, consider the following assembly source code example:
.section prog,code
L1: .pbyte 1
L2: .pbyte 2
L3: .pbyte 3
L4: .pbyte 4
.pbyte 5
.pbyte 6
.pbyte 7,8,9
In this example, the code
section attribute designates a section to be allocated in program memory, and the .pbyte
directives define individual byte constants. Since labels must resolve to a valid PC address, the assembler adds padding after each of the first three constants. Subsequent constants do not require padding. The following assembly listing excerpt illustrates the organization of these constants in program memory:
1 .section prog,code
2 000000 01 00 00 L1:.pbyte 1
3 000002 02 00 00 L2:.pbyte 2
4 000004 03 00 00 L3:.pbyte 3
5 000006 04 L4:.pbyte 4
6 05 .pbyte 5
7 06 .pbyte 6
8 000008 07 08 09 .pbyte 7,8,9
Constants 1, 2, 3 are padded out to a full instruction word and have unique PC addresses. Constants 4, 5, 6 are packed into a single instruction word and share the same address.