Z80 Assembly 03: Subroutines and The Stack (Saving Your Work)

Subroutines: Reusing Code A subroutine is a block of code designed to perform a specific task that can be called from anywhere in your program. This is how you avoid writing the same code repeatedly. The Two Commands: Command Action Analogy CALL NNNN Jumps to the address NNNN (the subroutine). Go to another room to perform a task. RET Jumps back to the instruction immediately following the CALL. Return to where you were before the task. The Stack: The LIFO Scratchpad The Stack is an area of memory managed by the Stack Pointer (SP). When you call a subroutine, the Z80 automatically uses the stack to save the return address. ...

September 27, 2025