avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] state machine.


From: Larry Barello
Subject: RE: [avr-gcc-list] state machine.
Date: Thu, 1 Jan 2004 13:46:05 -0800

Use the jump table.  Declare an array of pointers to functions in flash and
GCC will do the right thing.  Unfortunately you can't directly invoke the
function out of FLASH, but rather you will have to read in the address and
then call it.  It will be ugly in C, but turn into pretty optimal assembly
code.

Cheers!

-----Original Message-----
From: Herb Peyerl

So the project I'm currently building has a state diagram with 10
states, 7 inputs, and 4 outputs.  Each state has from 2 to 7
entry/exit points.

Now, I know how I would implement this in asm, and I know how I
would implement this in C on a big CPU with an operating system.
...


2 - Define an array of function pointers where each function pointer
    points to the relevant state.  Then my main() just loops infinitely
    calling the returned state as an index into the array.

My thoughts are that (1) is rather inelegant but will probably produce
the cleanest output... I'm not sure what (2) will translate to in terms
of asm output but would be probably the most elegant.  Will gcc produce
a neat little jump table if I do (2)?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]