Or, if you know you have 256 entries in your table: my_table_lookup: movlw high(my_table_data) movwf PCLATH movf table_index,W movwf PCL org X'300' ; use last 'page' for table my_table_data: retlw X'??' 254 more entries retlw X'??' ----- Original Message ----- From: "Olin Lathrop" To: Sent: Saturday, February 08, 2003 9:19 AM Subject: Re: [PIC]: AD 12F675 lockup > > Please ignore the question, I discovered that if the a/d value was 255, > the > > program would go off the end of my lookup table - because the table only > > has 254 entrys due to the addwf PCL,f at the start, therefore it > exceeeds > > the page when at 255. As my output is interrupt driven, the output > looked > > normal but wouldn't respond. > > ------------------------------------------ > > org 0x0200 > > MSB_Period > > addwf PCL,f > > retlw 0xXX > > (252 other retlw 0xXX) retlw 0xXX > > (0x300 page) > > This comes up periodically. Now that you've been penny wise and pound > foolish, do youself a favor and spend the little extra effort to do table > lookups the right way. The only excuse is the rather rare case where you > can't afford the few extra instructions or cycles. This table lookup code > has no restriction as to where the code or table resides in program > memory: > > ; > ; Return to the caller with the table value in W for the > ; 0-255 table entry number in OFFSET. The bank must > ; already be set for access to OFFSET. > ; > movlw high table ;get table start address high byte > movwf pclath ;init jump address high byte > movf offset, w ;get the 0-255 table entry offset > addlw low table ;make jump address low byte > skip_nc ;no carry into high byte ? > incf pclath ;propagate the carry > movwf pcl ;jump to the selected table entry > > ... > > table > retlw ... > ... > > > ***************************************************************** > Embed Inc, embedded system specialists in Littleton Massachusetts > (978) 742-9014, http://www.embedinc.com > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.