On Oct 26, 2005, at 7:18 PM, Dave Hylands wrote: > >> Interesting idea, I think in this case the table lookup would be the >> preferable way to go (no real memory constraints and constant >> time, but I >> think I'll keep a binary tree comparison in mind for possible >> future use. >> Always more than one way to skin a cat… Thanks again. > > Yeah - if the states values are "dense" (i.e. values like 0, 1, 2, 3, > 4, ...) then the lookup table will be faster and take up less memory. > If you're implementing something where the states are "sparse" (i.e. > values like 1, 17, 23, 24, 51) then using the binary search method > would be better. Is there any good reason the states have to be sparse? If there is nothing between 1 and 17 then just mark 17 as 2... Had one spent much time with a Microchip PIC16F87x one would be fluent in calculated jump tables as that is the only way to read an array of data from code space. No kidding, "ABCDE" translates into "RET A", "RET B", ... "RET E" and to get the Nth entry one JSRs to code immediately prior which adds the index to the program counter causing a skip to the return containing the desired data. On the 16F876 I created several "tasks" which never busy-waited. Each task used a state index to return to wherever it was previously, typically waiting on input. If no input then simply return. Next time around it will return back to the same input test based on the state index. If input then process it and bump the state index that the next time we do the next thing until the last which zeros the index on completion so the whole process starts over. Used the same indexed jump structure as required for constant string processing. Worked great for parsing incoming data frames. Actions based on the content of a frame could be controlled by branching to a different section of the state list. -- David Kelly N4HHE, dkelly@HiWAAY.net ======================================================================== Whom computers would destroy, they must first drive mad.
Message
Re: [AVR-Chat]
2005-10-27 by David Kelly
Attachments
- No local attachments were found for this message.