In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Hello "State-Engineers"... I can only agree - state machines can make programming a lot easier. I used them in my SX code as well as in many Windows applications that I wrote. Jon's sample code shows the typical "state-switcher", like this: [code] StateMachine mov w, State jmp PC+w jmp Here jmp There jmp Elsewhere Here ; some code ret There ; some code ret Elsewhere ; some code ret [/code] To select a specific state, the caller, or a routine inside the state machine would have to assign a number from 0 up to the highest allowed state (2 in the example above) to the State variable before calling or re-entering the machine, e.g.: [code] mov w, #1 ; Execute There call StateMachine [/code] Another version of a "state-switcher" may look like this: [code] StateMachine mov w, StateAddr jmp w Here ; some code ret There ; some code ret Elsewhere ; some code ret [/code] Here, the address of the code segment to be executed must be assigned to the StateAddr variable, like this: [code] mov w, #There call StateMachine [/code] Both methods have thiur pro and cons. The first version makes it easy to sequentially switch from one state to the next by simply inrementing the State variable, where the second version is more self-documenting and shorter. Have fun with FSMs! ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=242730#m243313 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)