Z80 Assembly 17: Bitwise State Machines (Managing Flags with BIT/SET/RES)

State Machines: Why Bitwise is Best A State Machine manages the status of a system (e.g., a game character is ‘Jumping’, ‘Firing’, or ‘Hit’). In high-level languages, you might use three separate Boolean variables for these. In Z80 assembly, that’s inefficient. By using a single register (like C) as a status register, you can manage up to eight independent Boolean flags, dedicating one bit to each status. This is the fastest method for context management. ...

September 27, 2025

Z80 Assembly 05: Logic Operations and Bit Manipulation

Logic Operations: AND, OR, and XOR These instructions perform bitwise logic operations between the Accumulator (A) and a source (another register or immediate value), storing the result back in A. They are crucial for filtering or combining specific data flags. The Core Logic Commands: Instruction Action Purpose AND N Bitwise AND (A = A & N) Filtering/Masking: Clears (forces to 0) any bits in A that are 0 in N. OR N Bitwise OR (A = A | N) Setting: Sets (forces to 1) any bits in A that are 1 in N. XOR N Bitwise XOR (A = A ^ N) Toggling: Flips the state (0→1, 1→0) of any bits in A that are 1 in N. Example: Filtering a Status Register If we only care about the highest two bits of a status register read into A: ...

September 27, 2025