Today you implement RST 0x00, a compact one-byte call to a fixed vector that reuses the stack machinery you already built - the very mechanism interrupts will lean on in the next chapter. It is the small, focused addition that rounds out control flow.
Implement RST 0x00 (a one-byte call to a fixed vector) and run a program that calls a subroutine and returns.
RST (opcode 0xC7 and its seven siblings) is a compact, one-byte CALL to one
of eight fixed vectors at 0x00, 0x08, 0x10, and so on up to 0x38. It
pushes the return address like any call, then jumps to its hardwired low address.
Games use them as fast calls to common routines, and - importantly - the
interrupt system reuses the exact same mechanism to jump into handlers, which you
will meet in the final chapter.
You now have everything for real control flow: jumps, conditional branches, the
stack, calls, returns, and restarts. Celebrate by assembling a program with an
actual subroutine - call it, let it run, watch RET bring you back - and
confirm the final state. That is a genuine structured program running on a CPU
you built from a single register up.
case 0xC7: // RST 0x00c.push16(c.PC) // PC already past the 1-byte opcodec.PC = 0x0000return 16// RST 0x08,0x10,...0x38 jump to those fixed low addresses
RST - one-byte calls to eight fixed vectors, also used by interrupts.