This is a tutorial paper on how to structure code for tiny microprocessors.
With this infrastructure, you can have several tasks running (apparently) independantly.
At its smallest, the over head of this design technique is only 18 lines of code.
The paper is presented in 2 parts: the first 10 pages outline the basic theory; the rest of the paper includes embellishments, examples of state code and general comments from my experience using this technique for almost 20 years.