The state machine model of this consists of a core with 3 type of data classification, Inputs, Outputs, and Feedback.
The goal is to create a memory table by where the inputs and the feedback compose the offset address in the table of the next state.
Events to the system cause it to update its outputs and feedback with regard to its inputs and feedback.
The methods here can be used for software state machines and for hardware state machines.
In the following tables I have hilighted the background of the parts in the tables that get used for an offset address.


--= Translators =--

Without feedback you have a translator, simple example:

Inputs
Outputs
A
B
X
Y
0
0
0
0
0
1
1
0
1
0
1
0
1
1
0
1
   
In C, this would simply be a lookup table.

--= Sequencers =--

Without Inputs, you have a sequencer, simple example:

1000 -> 0100 -> 0010 -> 0001 -> repeat

Feedback in
Feedback out
Outputs
A
B
A
B
W
X
Y
Z
0
0
0
1
1
0
0
0
0
1
1
0
0
1
0
0
1
0
1
1
0
0
1
0
1
1
0
0
0
0
0
1

Keep in mind that the feedback out does not occur to the feedback in until there is an event.
This can be implemented in a memory table where the feedback out is used as the offset to the next state. The table might look as follows in memory:

D7
D6
D5
D4
D3
D2
D1
D0
-
-
1
0
0
0
0
1
-
-
0
1
0
0
1
0
-
-
0
0
1
0
1
1
-
-
0
0
0
1
0
0

where D0 and D1 are used as the offset to the next state, and D2, D3, D4, D5 are used as the outputs.
as a hex dump this would look like

0000: 21 12 0B 04

it could be implemented in C as follows:


/*********************************************************/

unsigned char table[] = {0x21, 0x12, 0x0B, 0x04};
unsigned int offset = 0;

int main(void) {

   unsigned int output;

   while (1) { 
      output = table[offset] >> 2;     // shift out the bits used for feedback       
      offset  = table[offset] & 0x03;  // mask off outputs for next offset

      printf("%d/n", output);
   }

}
/***********************************************************/

I should also mention that this could be done without actaully having any dedicated outputs, you COULD, in this example, make it so that the feedback was used for both output and feedback.

--= State Machines =--

Combining Inputs and Feedback you have a state machine, simple example:

Input = 0:                  1000 -> 0100 -> 0010 -> 0001 -> repeat
Input = 1:  repeat <- 1000 <- 0100 <- 0010 <- 0001

Input
 Feedback in
Feedback out
Outputs
0
0
0
0
1
1
0
0
0
0
0
1
1
0
0
1
0
0
0
1
0
1
1
0
0
1
0
0
1
1
0
0
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
0
0
0
0
1
1
1
0
0
1
1
0
0
0
1
1
1
1
0
0
1
0
0

The offset address is now composed of the feeback AND an input, the input can change anywhere in the sequence, so you may want to be carefull of alignment of the outputs to the feedback for each input condition.
In this example the outputs will sequence to the right when input is 0, when input is 1, they will sequence to the left.

Again this is implementable in C:


/*********************************************************/

unsigned char table[] = {0x21, 0x12, 0x0B, 0x04, 0x0B, 0x04, 0x21, 0x12};
unsigned int offset = 0;

int main(void) {

   unsigned int output;
   unsigned int input;

   input = 0; // can be modified to 1

   while (1) { 
      output = table[offset] >> 2;                               // shift out the bits used for feedback       
      offset  = (input << 2) | (table[offset] & 0x03) ;  // construct offset to next state

      printf("%d/n", output);
   }

}
/***********************************************************/


-== Taking it up a notch =--

This is the part where I tell you that we dont really need CPU based computers, state machines will do just fine, but thats more than 1 notch, so I'll get there later.
In the last mentioned state machine, there was 1 input, that could either be on or off, this is pretty simplistic, in the real world your likley to have more complex inputs, lets say you have a direction for a robot to travel in, 4 of them, and maybe you want to throw in something else, like 4 bumpers. It really helps to be able to group and name these things.
In this program, a group of inputs, feedback, or outputs is called a factor. Each factor has states that it can be in. For example

Factor: Direction
States:  Forward, Left, Right, Reverse

In this case, the program will automatically work out that two bits need to be used for the factor direction.

Because of the nature of the table offset method that this uses, there needs to be a table that accounts for all combinations of input and feedback conditions, which is the first thing this program helps you with.
Once all the combinations of all the states have been laid out, the next task is linking them all up into your state machine.




- Multiple feedback columns to overlay tables