please dont rip this site

A Compact State Machine Engine by Ron Braithwaite

Basically there is a state variable, holding the current state, and a table. The first part of the table has a 16 bit offset to the start of the entries for the current state. The state entries have an input mask, an input match which is compared to the AND value of the input and the mask, the next state (if there is a match), and a subroutine that is executed and passed the input value. It is essential that the last state entry for every state have a mask and match of zero, with the subroutine an error handler. I always coded this in assembler for speed. The assembler pseudo-code looked something like this, with the assumption of 16 bit input and 16 bit offsets: {Ed: Ron is quoting from memory here}

move.w inputValue, r1
move.w currentState, r2
leftshift #4, r2 ; multiply by 16
move.w (r2+tableBase), r3
$1: move.w (r3)+, r4
and.w r1, r4
cmp.w r4, (r3)+ ; r3 pointed at inputMatch, inc to nextState
jmp.eq $2
add #ENTRYOFFSET, r3 ; offset to start of next state entry
jmp $1
$2: move.w (r3)+, r2
move.w r2, currentState
call (r3) ; subroutine must end with a return
This is pretty fast and can handle pretty much anything. If this is the core of an interrupt service routine, don't forget to turn interrupts back on as soon as possible. +
file: /Techref/method/process/states-rb.htm, 1KB, , updated: 2013/8/27 21:38, local time: 2024/6/15 01:28, owner: JMN-EFP-786,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> A compact state machine engine by Ron Braithwaite</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?


Welcome to!


Welcome to!