An RTOS..
Creates an operating system...
Usually a timer set to fire every 10mS or so.
You need several software stacks... Each stack mimic's a mini system.. We need to save all local variables and running registers...
The first task: - load the relevant task 1 program counter, working register, flag register and all local variables
execute x many commands.
The Second task: - load the relevant task 2 program counter, working register, flag register and all local variables
execute x many commands.
and so on..
One task is usually a watchdog ensuring that other tasks are behaving..
You really need a bit of data memory when using an RTOS... The smallest RTOS is around 6K of code space, so small and mid sized pics are out!!