← back to zenas

Write it, run it, test it

Most Z80 assemblers stop once they've produced bytes. zenas can also run what it just assembled, and check that the result is correct — all in one tool, without reaching for a separate emulator.

How it works

zenas run yourprogram.asm assembles and executes the result in a built-in Z80/Z80N core, reporting the final CPU and memory state — registers, flags, any memory range you ask for. You can cap the run at a fixed number of instructions, run to a specific subroutine and stop on return, preload data into memory first, or trace every instruction as it runs.

zenas assert takes it further: give it an expected outcome — a register value, a flag, a specific memory address — and it runs the program, checks the result, and tells you pass or fail.

Real, repeatable tests

Name a routine test_something in a file ending _test.asm, and annotate it with an .EXPECT directive stating what should be true when it returns. Run zenas assert against the file with no other arguments, and it finds every annotated test, runs each one, and reports results the way a modern test runner does — pass, fail, and a summary — with a non-zero exit code on failure so it plugs straight into a build script or CI.

.MATCH extends this to comparing a whole block of memory against expected bytes, useful for checking that a routine produced the right data, not just the right registers.

Why it matters

Writing Z80 assembly by hand is unforgiving — a wrong opcode, an off-by-one in a loop counter, a flag you assumed was set. Being able to write a test alongside the routine it's testing, and get an immediate pass/fail the moment you assemble, catches those mistakes at the point you make them instead of three hours into debugging a loaded program on a real or emulated machine.