eblc1388
Active Member
Hi,
I need to do a lookup table that span page boundaries. Therefore I have to do a 13-bit offset call. I look up Microchip's datasheet and found one but it trashes my offset value in doing the call. So I try to write my own version that does not trash my offset value. It comes up shorter than the Microchip's one.
Common sense tells me that a "better" solution is often the results of overlooking some important issues.
Can you spot any errors/shortcomings in the code I use?
Thanks for your comments.
I need to do a lookup table that span page boundaries. Therefore I have to do a 13-bit offset call. I look up Microchip's datasheet and found one but it trashes my offset value in doing the call. So I try to write my own version that does not trash my offset value. It comes up shorter than the Microchip's one.
Common sense tells me that a "better" solution is often the results of overlooking some important issues.
Can you spot any errors/shortcomings in the code I use?
Code:
Example by Microchip, trash value in OFFSET file reg
====================================================
org 0x80
movlw LOW Table ;get low 8 bits of address
addwf offset,F ;do an 8-bit add operation
movlw HIGH Table ;get high 5 bits of address
btfsc status,c ;page crossed?
addlw 1 ;yes then increment high address
movwf PCLATH ;load high address in latch
movf offset,w ;load computed offset in w reg
;
call Table
;
;
Table:
movwf PCL,F ;load computed offset in PCL
retlw ’A’ ;return the ASCII char A
retlw ’B’ ;return the ASCII char B
retlw ’C’ ;return the ASCII char C
EXAMPLE: My version, shorter, does not destroy OFFSET value
===========================================================
org 0x80
movlw HIGH Table ;get high 8 bits of Table address
movwf PCLATH ;save to PCLATH (may not be correct, yet)
movlw LOW Table ;get Table low address
addwf offset,W ;add value of offset, keep result in W
;if page is crossed, carry will be set
btfsc STATUS,C ;check page crossed? Skip next if NO
incf PCLATH ;yes, increment PCLATH
;
call Table ;call to table
;
;
Table:
movwf PCL,F ;load computed offset to PCL
retlw 'A' ;return the ASCII char A
retlw 'B' ;return the ASCII char B
retlw 'C' ;return the ASCII char C
Thanks for your comments.