Z80 Assembly 47: Debugging with the Stack (Crash Analysis)

The Value of the Stack in Debugging When a Z80 program crashes, the CPU registers often hold garbage data. The Stack, however, holds the historical sequence of return addresses created by every CALL instruction. Examining the stack is the primary method to determine how the program arrived at the crash point—the call chain. The Principle: You read the values on the stack, and these values are the addresses of the instructions immediately following the last few CALL commands. ...

September 27, 2025

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