Z80 Assembly 51: Choosing Your Tools (Assemblers and Emulators)

The Modern Z80 Toolchain Since you are writing Z80 code on a modern computer (like a Linux LXC), you need a cross-assembler to translate your mnemonics into machine code and an emulator to run and debug that machine code. Choosing a Cross-Assembler A cross-assembler runs on one type of machine (x86 Linux) but produces code for another (Z80). Popular Assemblers: Assembler Focus Key Features Z80Asm Generic Z80/Z180 Simple, fast, and highly compatible with many old Z80 dialects. sjasmplus ZX Spectrum / MSX Powerful modern assembler with rich macro support, binary includes, and comprehensive error checking. WLA DX Multi-platform Supports Z80, GameBoy, and other 8-bit CPUs, good for cross-platform projects. Assembler Directives Revisited: Be aware that directives like `DEFS′ (define space) or macro syntax (Part 20) can vary widely between assemblers. Always check the manual for your chosen tool. ...

September 27, 2025

Z80 Assembly 20: Writing a Simple Macro (Code Generation)

What is a Macro? A macro is a sequence of instructions or data definitions that you define once and can then reuse multiple times throughout your code by simply typing the macro’s name. When the assembler encounters the macro name, it substitutes the entire predefined block of code in its place. Macro vs. Subroutine: Subroutine (CALL): Saves memory by running one copy of the code, but is slower because it incurs the overhead of the CALL and RET instructions (17 cycles). Macro: Faster because the code is pasted directly (inline) every time it’s used, but increases the size of the assembled program. Defining a Simple Macro The syntax for defining a macro varies slightly between assemblers (e.g., TASM, Z80Asm, sjasmplus), but they typically use MACRO and ENDM or DEFM. ...

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