Something like this would work for two tasks in the same page. A more generic solution would be an interesting challenge but seemingly doable. Certainly this kind of thing is way more efficient than using explicit state machines. context equ 0x20 switch macro ; macro to switch tasks movlw $+2 ; load return 'return' address goto dispatch endm org 0 goto 4 org 4 ; init task switcher movlw task2 ; 'suspend' task 2 movw context ; fall into task 1 task1 do some stuff switch do some more stuff switch etc. goto task1 task2 do some stuff switch blah goto task2 dispatch xorwf context,f ; exchange w and context xorwf context,w xorwf context,f movw pcl ; jump to old context