9.1.4.1 Computed GOTO
A computed GOTO is accomplished by adding an offset
to the Program Counter. An example is shown in the following code example.
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 will advance and must 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.
Computed GOTO Using
an Offset Value
RLNCF OFFSET, W ; W must be an even number, Max OFFSET = 127 CALL TABLE ORG nn00h ; 00 in LSByte ensures no addition overflow TABLE: ADDWF PCL ; Add OFFSET to program counter RETLW A ; Value @ OFFSET=0 RETLW B ; Value @ OFFSET=1 RETLW C ; Value @ OFFSET=2 . . .
