How about even shorter (see caveats below): movlw high(case) ;Set upper byte of PC latch movwf PCLATH movf KeyNumber,0 addwf PCL,1 Case goto Switch1 goto Switch2 goto ... Caveats: 1) Only works if all possible values are sequential, starting with 0 (XOR method works with any set of values). 2) Of course you should (must) verify that KeyNumber is within the valid range before adding to PCL. 3) Must set PCLATH before the jump table 4) Make sure that the jump table does not cross page boundaries On Friday, February 13, 1998 7:52 AM, Andrew Warren [SMTP:fastfwd@IX.NETCOM.COM] wrote: > H.P. de Vries wrote: > > > I hope someone can help me with this, because I dont have any bright > > ideas right now ;) Is there a nifty little piece of code out there > > what does the same as the "case", e/g/ "switch" statement? > > > > I am creating a MIDI-controller board with a 16-button interface. > > Depending on which button is pressed, I want to branch to another > > pice of code. Who can help?? > > Hans: > > There are many ways to do this... Here's how I usually manage it: > > CASE: > > XORLW 1 > BZ W_CONTAINED_1 > > XORLW 2^1 > BZ W_CONTAINED_2 > > XORLW 3^2 > BZ W_CONTAINED_3 > > etc... > > This method takes 3 words (and 3 cycles) per test. There are > faster/shorter ways, but they generally require your "cases" to be > consecutive numbers. The method shown above will work with ANY > numbers; it could just as easily have been: > > CASE: > > XORLW 7 > BZ W_CONTAINED_7 > > XORLW 51^7 > BZ W_CONTAINED_51 > > XORLW 12^51 > BZ W_CONTAINED_12 > > -Andy > > === Andrew Warren - fastfwd@ix.netcom.com > === Fast Forward Engineering - Vista, California > === http://www.geocities.com/SiliconValley/2499 >