Two programs, one CPU
The finale: an operating system for the CPU you built. Each program gets its own registers and program counter (a process!); your kernel runs each for at most quantum instructions, switches on a SYS 1 (yield), and logs what each program prints — round robin, on real machine code you assembled.
A process is a machine state
Each program gets its own newMachine(): its own registers, program counter and output. That object *is* the process's context. Switching processes means choosing which machine object to pass to step next — the CPU code doesn't change at all, exactly as a real kernel reuses the same hardware with saved and restored register sets.
- Process = { name, words, machine }.
- Ready queue = array of processes in turn order.
- Context switch = pick a different machine object.
- Terminated = machine.halted is true; drop it from the queue.
Assemble every program once at the start; the kernel only ever deals with machine words.