Thu Aug 16 17:47:40 EDT 2018
So CPU works
Next: don't use it!
Seriously though, there is a middle ground here: generating state
machines from static programs.
Here's the outline of a practical program I need to write. The
input/output are abstracted, but essentially they perform two kinds of
- write to a register
- send a start pulse
- wait for a done pulse
- n times:
- m times:
- n times
- write, pulse
The essence of this structure is the nesting.
To flatten this requires flattening out the nesting.
What makes a CPU interesting is that it can do loops
A stack then adds nested loops
To translate all that into a state machine requires state for each
level + possibly repurposing the state for the next loop.
I don't even have to work this out to know that the CPU approach is
_much_ simpler once there is any form of nesting.
Note that a UART already performs nesting:
- top level states: idle->start->data->stop->idle
- inside data there are N data states
So to create a UART, one could also just create a CPU.
Let's look at that in the next post.