English
Language : 

PIC18LF2X_13 Datasheet, PDF (73/560 Pages) Microchip Technology – PIC18(L)F2X/45K50 USB Flash MCU Product Brief
EXAMPLE 5-1:
CALL SUB1, FAST


FAST REGISTER STACK
CODE EXAMPLE
;STATUS, WREG, BSR
;SAVED IN FAST REGISTER
;STACK
SUB1 

RETURN, FAST
;RESTORE VALUES SAVED
;IN FAST REGISTER STACK
5.2.2
LOOK-UP TABLES IN PROGRAM
MEMORY
There may be programming situations that require the
creation of data structures, or look-up tables, in
program memory. For PIC18 devices, look-up tables
can be implemented in two ways:
• Computed GOTO
• Table Reads
5.2.2.1 Computed GOTO
A computed GOTO is accomplished by adding an offset
to the program counter. An example is shown in
Example 5-2.
A look-up table can be formed with an ADDWF PCL
instruction and a group of RETLW nn instructions. The
W register is loaded with an offset into the table before
executing a call to that table. The first instruction of the
called routine is the ADDWF PCL instruction. The next
instruction executed will be one of the RETLW nn
instructions that returns the value ‘nn’ to the calling
function.
The offset value (in WREG) specifies the number of
bytes that the program counter should advance and
should be multiples of two (LSb = 0).
In this method, only one data byte may be stored in
each instruction location and room on the return
address stack is required.
EXAMPLE 5-2:
COMPUTED GOTO USING
AN OFFSET VALUE
ORG
TABLE
MOVF
CALL
nn00h
ADDWF
RETLW
RETLW
RETLW
.
.
.
OFFSET, W
TABLE
PCL
nnh
nnh
nnh
PIC18(L)F2X/4XK22
5.2.2.2 Table Reads and Table Writes
A better method of storing data in program memory
allows two bytes of data to be stored in each instruction
location.
Look-up table data may be stored two bytes per
program word by using table reads and writes. The
Table Pointer (TBLPTR) register specifies the byte
address and the Table Latch (TABLAT) register
contains the data that is read from or written to program
memory. Data is transferred to or from program
memory one byte at a time.
Table read and table write operations are discussed
further in Section 6.1 “Table Reads and Table
Writes”.
 2010-2012 Microchip Technology Inc.
DS41412F-page 73