>> Andrew Warren has given an optimal implementation of a >> switch statement. However, for its interest, here is >> a modestly tidied-up version of the original loop. > >[table-driven switch statement deleted] > >Cute, but your approach uses 13 cycles per case, at a savings of at most >one byte per. On that basis I would have to regard Andy's as being better >all around. Cute?? My intention wasn't to produce a time-optimised version of a sparse table lookup. Rildo Pragana put up an implementation that used array indexing and a loop, and I wanted to show Rildo a variation of this technique. Looking at Rildo's code you see he keeps an array index, and then calculates an array offset on each of the two occasions he accesses the array. This is suggestive of a high level programmer who has 'hand compiled' the code. Most low level programmers would take the approach of just stepping straight through the array. I wanted to show this. >That does not mean it cannot be improved upon, though. :-) >On a non-5x/non-508 part, you may use the addlw instruction to improve >things a bit. For example, [hopefully I'm doing this right]... suppose you >need to distinguish Y or y, N or n, and 0-9. > >[switch statement deleted] > >The use of 'addlw' rather than 'xorlw' allows the program to check for ranges, >and to perform a binary search. The only downside is that the code can get >more complicated (even if it's faster/shorter) than with the 'xorlw' approach. The problem specification was to search a list of arbitrary values. To redefine the problem specification to include value ranges and sorted values, and to then declare a solution to this modified problem an 'improvement' is kinda cute. ___Bob