Show HN: Preemptive Multitasking on an AVR Microcontroller
Ahhh this reminded me of when I as a teen saved up and bought &quot;Assembly Language Master Class&quot;[1], the only assembly-related book I could find in my local bookstore that didn&#x27;t look like a complete intro-book. I had learned a bit of asm from some articles I had downloaded from various BBSes, and wanted to take the next step.<p>After reading through it a few times I got the idea to try to write a pre-emptive scheduler myself. This was way before the internet so I just knew the concept existed, and the book didn&#x27;t have anything like that in it per se. So I spent a day or two figuring out by my self how to preserve and restore the registers and flags without disturbing them.<p>I wrote it in Turbo Pascal, using the inline asm for the task switcher. Each &quot;process&quot; was just a procedure (subroutine) that ran in a loop until a global bool was set.<p>I decided to hook the RTC[2] for switching tasks, but nothing more. So each time-slice was fixed at 18.2ms which didn&#x27;t make things terribly interactive.<p>Never got further, it was more of a &quot;can I do it&quot; type project, but boy that feeling when I saw my three &quot;processes&quot; running one after another without cooperation... priceless!<p>[1]: <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Assembly-Language-Master-Class-Press&#x2F;dp&#x2F;1874416346" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Assembly-Language-Master-Class-Press&#x2F;...</a><p>[2]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Interrupt_request_(PC_architecture)#Slave_PIC" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Interrupt_request_(PC_archit...</a>