Mike Keitz wrote: > > On Wed, 25 Jun 1997 22:29:54 +0200 "Michael Giuggio (Tel (860)763-6861)" > writes: > >I apologize for the relatively simplistic question re: RTFM material. > >I am writing my first PIC '84 program. > > > >It maps out to 01BE in length in terms of EPROM used for the program > >(via the xxxx.LST output file from MPASM). > > > >When adding YANF (Yet Another Neat Feature) ... (actually fix a bit of > >bad > >logic) the length increases past this length (to 01AD for example). > > > >The program now does not function. It appears that the if I have the > >functioning program and continuously add nops to the program I can get > >to a > >point where the program ceases to function > > <...> > > What has probably happened is the extra code inserted has moved some of > the targets of computed jumps (usually used to access RETLW tables) out > of the first 256 program words. Unless you set the PCLATH register > otherwise, ADDWF PCL,f MOVWF PCL, etc. will always land in 256 word > "page" 0 (PC=00XX). For example, if you have a table at 0xFE: > > ; This instruction is at 0xFE now. Before adding a neat feature, it was > at ; 0xF0, and the program worked then. > gettabl addwf PCL,f > retlw 05 > ; Next instruction is at 0x100. This is bad. > retlw 08 > retlw 03 > retlw 04 > > If you call gettabl with 2 in W, expecting it to return 8, suprise. What > will actually happen (if PCLATH is still 0) is the PIC will jump to 0000, > starting the program over as if a reset had occurred. Not good. > > I find it convenient to move all the RETLW tables and other targets of > computed gotos up to page 3 with an ORG h'300' directive, then set PCLATH > to 3 while initializing all the TRIS registers, etc. after reset. The > tables will then stay put if code is added or removed from the rest of > the program. Or you can put all the tables in first, then org the rest > of the program to 0x100. Hi! Try this: it allows you to put your lookup tables wherever you want 'em. You can even put them ON the edge of the first page and run over to the second page. ;===================LOOKUP TABLE LOOKUP MOVWF OFFSET ;MOVE MOVLW HIGH BASEADD ;LOAD HIGH BYTE OF BASE ADDRESS INTO W MOVWF PCLATH ;HIGH BASEADD INTO PC-LATCH MOVLW LOW BASEADD ;LOAD LOW BYTE OF BASE ADDRESS INTO W ADDWF OFFSET,W ;ADD OFFSET TO PC LOW !!-->> BTFSC STATUS,C ;TEST FOR ROLL-OVER IN PC !!-->> INCF PCLATH ;INCREMENT PCLATH IF ROLL-OVER DETECTED MOVWF PCL ;LOW BASEADD INTO PCL BASEADD RETLW B'01111101' ;1 - DUD! DUE TO MOD8 INCREMENTING TO 1 RETLW B'01111101' ;1 RETLW B'10101010' ;2 RETLW B'01101010' ;3 RETLW B'11100100' ;4 RETLW B'01111000' ;5 RETLW B'10101100' ;6 RETLW B'01101001' ;7 -- eric van es vanes@ilink.nis.za cape town, south-africa