Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

State Machine Coding (was no subject)

2005-10-26 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, Martin Jay McKee 
<MartinJayMcKee@d...> wrote:
> I'd like to find a way to minimize the difference between the
> run times of the subroutine for states 1 and state N.

Instead of using a sequential set of comparisons (sometimes called a 
skip chain), use a dispatch table instead.  The table would contain 
code space addresses, you index it with the state value (after 
checking validity), load the address from the table into r31:30, and 
them do an ijmp or icall.  (Your target processor may or may not 
support these instructions.)

As a side note, in the code that you showed the clz instruction is 
superfluous.  The compare instruction will either set or clear the Z 
flag depending on the values.

Don

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.