Hi Rikard, here find an example of how you can solve your problem. The code is self explaining... You can change the goto with retlw of course but not the order of the instructions that do the jump! Bye Nic ;************************ starthere movlw high(JumpTable) ;load high address byte in PCLATH movwf PCLATH movlw JumpTable addwf TableIndex,w ;TableIndex from 0 to number of items -1 btfsc STATUS,C ;check Carry flag incf PCLATH,f ;gotcha! movwf PCL ;now jump safely JumpTable goto FirstPoint goto SecondPoint goto ThirdPoint JumpTableEnd ;********************* Rikard Bosnjakovic wrote: > Consider this code: > > default_minutes: > addwf PCL, f ; jump table > retlw .5 > retlw .10 > retlw .15 > retlw .20 > > When it was in the beginning of my code, PCL was below 0xff, it > worked. When tidying my code I moved the above to the bottom of the > source, and the code went totally havoc. After 20 minutes of > debugging, I found that two lines before it, PCL overflowed and turned > into 0x00, making the jump-table return a value which made the goto go > to the beginning of the code! > > It's easily solvable by moving "default_minutes" to a place near the > top of the source, but is there any way you can solve it in other > ways? I mean, since the chip (16F886) got 8kb program stack, PCL must > be able to keep track of all 8kb data. > > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist