I'm having trouble getting my head around this. I want to add a two-byte offset to TBLPTR to read a large table. I tried to:
add the low byte to TBLPTRL inc TBLPTRH if carry is true inc TBLPTRU if carry is true again add the high byte to TBLPTRH inc TBLPTRU if carry is true
Without the code between the comments, the routine returns the first word in TABLE0 properly. What am I missing?
TABLE_TO_TEMP MOVLW LOW TABLE0 MOVWF TBLPTRL
MOVLW HIGH TABLE0 MOVWF TBLPTRH
MOVLW UPPER TABLE0 MOVWF TBLPTRU
RLCF TEMPLO ; multiply offset by RLCF TEMPHI ; 2 for word-size data
; ======== calculate offset into table MOVF TEMPLO ADDWF TBLPTRL, 1 ; changes from 7A to 7F ; when templo=0x00. WTF?!?
BTFSC STATUS, C ; did we wrap? CALL INCTABLE ; inc hi/upper
MOVF TEMPHI ADDWF TBLPTRH, 1 ; add high byte BTFSC STATUS, C ; did we wrap? INCF TBLPTRU ; inc upper
; ======== perform read; put data in TEMP vars TBLRD*+ MOVFF TABLAT, TEMPLO TBLRD* MOVFF TABLAT, TEMPHI
INCTABLE INCF TBLPTRH ; inc high byte BTFSC STATUS, C ; did we wrap again? INCF TBLPTRU ; if so, inc upper RETURN
TABLE0 dw 0xAABB, 0xCCDD, 0xEEFF, 0xFFAB, 0x0004, 0x0005, 0x0006,0x0007 ; etc.