> How about this: > > movfw COMND ;get you command into w > addwf PCL ;add offset to pc to generate > ;computed goto > > Make sure you never give COMND a command value higher than the number of > goto > statements you have! I prefer to use [assuming, e.g., 28 commands]: movf COMND,w ; "Official" form for movfw, though movwf is ; nice if your assembler will take it. andlw 31 ; Next power of two over number the number of ; commands, minus one addwf PC ; Or addwf PCL [the 28 commands] goto Oops goto Oops goto Oops goto Oops If the number of commands is slightly over a largish power of two, then I spring for the compare-against-maximum, but otherwise the andlw is cheap insurance (one cycle, and one byte for it and every "goto Oops" that's needed). If the number of "goto Oops"s would be objectionable and my program needs to have any data tables within it, I sometimes do this (assuming I have a 40 entry command table, a 20 byte data table, and an 8 byte data table) CommandParse: movf command,w andlw 63 addwf PC [the 40 commands] Data1: andlw 31 addwf PC [the 20 RETLW's for the first table] Data2: andlw 7 addwf PC [the 8 RETLW's for the second table] retlw 0 ; In case Data1 was called with 30 or 31 retlw 0 ; In case Data1 was called with 30 or 31 Using this approach, an overrun on the commandparse table will result in an RETLW [something] being executed in fairly short order, as will an overrun on either of the data tables. The extra code required, however, is nothing beyond the "andlw"'s and the two extra RETLW's at the end. Not at all bad given the level of bullet-proofing it achieves.