Z80 Assembly 11: Self-Modifying Code and Look-Up Tables

Look-Up Tables (LUTs): Trading Memory for Speed A Look-Up Table (LUT) is a pre-calculated block of data stored in memory. Instead of performing a time-consuming calculation (like a sine function or a multiplication), the CPU simply uses the input value as an index to quickly read the pre-computed result. How to Use a LUT: Use the input value (N) to calculate the offset within the table. Add this offset to the table’s starting address. Read the byte (result) at that final calculated address. Example: 10-Value Square Root Table ...

September 27, 2025

Z80 Assembly 10: Interrupt Modes and Handling External Events

What is an Interrupt? An interrupt is an external signal from a hardware device (like a timer or keyboard controller) that tells the CPU to immediately stop what it’s doing and execute a specific routine to handle the event. This is how the system maintains responsiveness. The Two Key Commands: Instruction Action Purpose EI Enable Interrupts Allows the CPU to listen for and respond to external interrupt requests. DI Disable Interrupts Prevents the CPU from responding to external requests (used for critical code sections). The routine that handles the interrupt must end with RETI (Return from Interrupt) or RETN (Return from Non-Maskable Interrupt) instead of a simple RET. ...

September 27, 2025

Z80 Assembly 08: Multi-Byte Math and the Alternate Registers

Arithmetic with Carry: ADC and SBC When adding numbers larger than 8 bits (like a 16-bit word or a 32-bit integer), you must add the Carry flag (C) from the previous operation into the current one. This is done with the ADC and SBC instructions. The Principle: Add (or Subtract) the current byte PLUS the Carry flag. Instruction Action Purpose ADC A, R A ← A + R + C Add with Carry: Used to link the result of the previous 8-bit addition. SBC A, R A ← A - R - C Subtract with Carry/Borrow: Used to link the result of the previous 8-bit subtraction. Example: 16-bit Addition (BC + DE) ...

September 27, 2025