r0mheat z80 lessons · interactive course
Learn how a Z80 runs a program
Follow assembly one instruction at a time. Watch the program counter fetch bytes, registers change, flags respond, and memory receive data.
A clear path through the material
New to number systems? Begin with bits. Then follow the numbered lessons in order. Hardware pages are useful references at any point.
Number basics
Build the ideas used by assembly
Bits are the values the CPU stores and changes. These pages explain binary, hexadecimal, signed values, and the addresses used to find data.
- BASICSBinary numbers
Bits and place values
- BASICSBinary addition
Add bits and follow the carry
- BASICS16-bit numbers
Extend binary place values to 16 bits
- BASICSHexadecimal numbers
Digits, place values and Z80 notation
- BASICSNegative numbers and two’s complement
Read signed values in binary and hexadecimal
- BASICS16-bit addresses and memory maps
Address space, ranges, offsets and common sizes
Hardware references
Open these alongside any lesson
See the Z80’s register set and flags, then follow address, data, control, and clock signals between the CPU and the rest of the computer.
- REFRegisters and flags
What each Z80 register stores and how flags describe results
- REFCPU buses, clock and pins
Follow addresses, data and control signals
Course roadmap
Lessons 00–26 · follow the numbers
Each lesson builds on earlier instructions. Use Step to execute one instruction, Run to watch the program, or Step back to inspect a previous state.
Foundations
Lessons 00–03
- 00How a CPU runs code
Registers, memory and fetch-execute
- 01Loading data
LD instructions and memory
- 02Arithmetic and flags
ADD, SUB, INC and DEC
- 03Comparing and jumping
CP, JP, JR and conditions
Loops, memory and CPU tools
Lessons 04–13
- 04Loops
DJNZ and counted loops
- 05Block copy
LDIR and block transfers
- 06The stack
PUSH, POP, CALL and RET
- 07Logic and bits
AND, OR, XOR and bit operations
- 08Signed numbers and arithmetic flags
Two’s complement, carry, half-carry and overflow
- 09Bit masks, rotates and shifts
Select bits and move them through a byte
- 10Index registers and addressing
Use IX and IY with signed offsets
- 11Exchange and shadow registers
Swap values and use the alternate register set
- 12Subroutines in practice
Pass values, preserve registers and return
- 13Block copy and search
Use forward and backward block instructions
Text, numbers and data
Lessons 14–19
- 14Text and console output
Write characters to a generic text screen
- 15Strings, fast fill and copy
Work with byte ranges in memory
- 16Lookup and jump tables
Use data tables to select values and code paths
- 17BCD numbers and DAA
Store decimal digits and adjust sums
- 18Printing decimal numbers
Convert a value into text digits
- 19Checksums
Detect changes in a block of data
Search and algorithms
Lessons 20–22
- 20Sorting
Order a small list of bytes
- 21Binary search
Search a sorted table by halving the range
- 22Random numbers
Build a repeatable pseudo-random sequence
Interrupts and project
Lessons 23–25
- 23Interrupts
Respond to events outside the main program
- 24Short Z80 idioms
Recognize compact instruction patterns
- 25Final project: text screen
Combine the course in a small screen program
Program files and memory
Lessons 26–26
- 26COM files and memory layout
ORG 0100h, code, data, PSP and stack