Z80 Assembly 56: Error Handling and System Traps (Preventing Crashes)

The Need for Error Trapping In an operating system, a single unexpected event—such as a user program attempting to execute an illegal opcode or writing to protected memory—can lead to a total system crash. Error Trapping is the mechanism the OS uses to catch these faults and recover gracefully. Trapping Illegal Instructions The Z80 itself does not automatically trap illegal opcodes (machine code bytes that don’t correspond to any instruction). Executing an illegal opcode usually results in unpredictable behavior or a very slow, unintended operation. ...

September 27, 2025

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 14: Directives, Labels, and Debugging Techniques

Assembler Directives: Structuring Your Code Assembler directives are commands that are read and acted upon by the assembler program, not the Z80 CPU. They organize code, reserve memory, and define data. Directive Action Purpose ORG NNNNH Sets the origin (starting address) where the following code should be placed in memory. Essential for defining where your program loads. EQU symbol, value Equates a symbolic name to a numerical value. Defines constants like port addresses or screen dimensions (SCREEN_WIDTH EQU 32). DB val1, val2, ... Define Byte: Reserves memory and places 8-bit data bytes (numbers or ASCII characters). Used to define text strings or data tables. DW val1, val2, ... Define Word: Reserves memory and places 16-bit words (often addresses). Used for jump tables or storing address pointers. DEFS N Define Space: Reserves N bytes of uninitialized memory. Used for buffers, variables, or the stack area. Example: Data Definition ...

September 27, 2025