Searching \ for '256-boundary check in tables' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=table
Search entire site for: '256-boundary check in tables'.

Truncated match.
PICList Thread
'256-boundary check in tables'
1999\11\23@183112 by Morgan Olsson

picon face
In the thread "A-D on PIC 16C73B" , table boundary problem was mentioned.

Automatic compile time check to see if the last entry in the table is in the sam
e 256-instr block:

        code before the table...
        :
        :
        addwf PCL,F
first   goto ...  ;First table entry
        goto ...
        :
        :
        goto ...
last    goto ...  ;Last table entry

        IF high last != high (first-1)
        ERROR "addwf PCL overflow in table; relocate or divide in part"
        ENDIF

Note that also the ADDWF PCL,F must be in the same 256-instr block as the rest o
f the table, therefor the "(first-1)".



And if the table is called or gotoed it it is nice to have CALLTABLE / GOTOTABLE
macros that sets PCLATH correctly.



Also a runtime check of the input value can be made.
Protects and can help finding bugs
This one jumps to errorhandler, but another solution could be clearing Pointer,
depending on application.

        movf    Pointer,W
        sublw   last - first
        btfss STATUS,C  ;Um... did I get the subtraction right? (midnight...)
          goto errorhandler
        movf    Pointer,W
        addwf PCL,F
first   goto ...
        goto ...
        goto ...
        goto ...
        goto ...
last    goto ...  ;Last table entry

        IF high last != high (first-1)
        ERROR "addwf PCL overflow in table; relocate or divide in part"
        ENDIF

Regards
/Morgan

1999\11\23@191308 by Tony Nixon

flavicon
picon face
Morgan Olsson wrote:
>
> In the thread "A-D on PIC 16C73B" , table boundary problem was mentioned.


If a value in ram is specified for a 256 element lookup table then this
may help deal with boundary issues. There are probably better methods
around also.


       movlw high ($ + 8)
       movwf pclath
       movf RAMx,w
       addlw low ($ + 6)
       btfsc Status,Carry
       incf pclath
       movf RAMx,w
       addwf pcl
       retlw 0h
       retlw 1h
       etc...

--
Best regards

Tony

http://www.picnpoke.com
Email spam_OUTsalesTakeThisOuTspampicnpoke.com

1999\11\24@032731 by paulb

flavicon
face
Morgan Olsson wrote:

> Automatic compile time check to see if the last entry in the table is
> in the same 256-instr block:

 Mmmm.  Should that not be a macro?  Only problem would be string
substitution in the error message.

first   goto ...  ;First table entry
        goto ...
        :
        :
        goto ...
last    goto ...  ;Last table entry

 CHECK256 first,last
--
 Cheers,
       Paul B.

1999\11\24@085345 by Morgan Olsson

picon face
Hej Tony Nixon. Tack fšr ditt meddelande 01:08 991124  enligt nedan:
{Quote hidden}

Looking good

There is a similar solution in AN556d , example 5, where calculations are done before calling/gotoing the table.

Wold make a nice macro.

Problem i the many extra cycles; a table itself is very fast.

If we first make a macro of the compile time check, to put at end of table, we then will get a message if we need to implement your or solution above (or ex 5 in AN556d).  Could be easy and clear to implement as a macro.


/Morgan

1999\11\24@102310 by Tracy Smith

picon face
--- Tony Nixon <.....Tony.NixonKILLspamspam@spam@ENG.MONASH.EDU.AU> wrote:
{Quote hidden}

Here's a method that's better. I first saw something
like this posted by mike kietz about 2 years ago.

  movlw  high   (TABLE_START)
  movwf  pclath
  movf   index,w
  addlw  TABLE_START
  skpnc
   incf  pclath,f
  movwf  pcl
TABLE_START
  retlw  ...

If the table is called such that W is the index:

  addlw  TABLE_START
  movwf  temp
  rlf    known_zero,w
  addlw  high(TABLE_START)
  movwf  pclath
  movf   temp,w
  movwf  pcl
TABLE_START

.lo
__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one place.
Yahoo! Shopping: http://shopping.yahoo.com

1999\11\24@110924 by Morgan Olsson

picon face
Nice, Tracy :)

Perfect for macronization

/Morgan

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...