title "ArbTable - Tables Longer than 256 Entries."
;
; This Program demonstrates how a table that is longer than
; than 256 entries (and therefore, jumps over the 256 "addwf PCL"
; Page boarder).
;
LIST p=16f877,f=inhX32
#include <p16f877.inc>
__CONFIG _CP_OFF & _WDT_OFF & _RC_OSC
; Registers
CBLOCK 0x20
TableOff:2
Temp
ENDC
; PAGE
; Mainline of ArbTable
org 0
loop:
movlw 9 ; Get the 10th Message
call GetMSG
MOVF 0X20,W
MOVWF PCLATH
MOVF 0X22,W
NOP
nop
goto loop
GetMSG ; Figure Out where the Specified
; Message is
movwf Temp ; Save the Message Count
clrf TableOff ; Reset the Table Values
clrf TableOff + 1
GM_Loop
movf Temp, f ; If Temp == 0, then Stop Search
btfsc STATUS, Z
goto GM_End
call MSGTable ; get the Value in the Table
iorlw 0 ; Are we at the End of a Message?
btfsc STATUS, Z
decf Temp, f ; Yes - Decrement Temp
incf TableOff, f ; Point to the Next Table Element
btfsc STATUS, Z
incf TableOff + 1, f
goto GM_Loop
GM_End ; Tbllo/TblHI Now Point to the
; First Character in the Specified
return ; Message
MSGTable ; Place all the Messages Here
movlw TableStart ; Setup PCLATH for the Table
addwf TableOff + 1, w
movwf PCLATH
movlw TableStart & 0x0FF ; Figure out the Offset
addwf TableOff, w
btfsc STATUS, C ; If Necessary, Increment PCLATH
incf PCLATH, f ; to get the Correct 256 Address Page
movwf PCL ; Update the PC
TableStart ; Table Data
Msg0
dt "This is the First Message #1", 0
Msg1
dt "This is the Second Message", 0
Msg2
dt "This is the Third Message", 0
Msg3
dt "This is the Forth Message", 0
Msg4
dt "This is the Fifth Message", 0
Msg5
dt "This is the Sixth Message", 0
Msg6
dt "This is the Seventh Message", 0
Msg7
dt "This is the Eigth Message", 0
Msg8
dt "This is the Nineth Message", 0
Msg9
dt "This is the Tenth Message", 0
end