Z80 Assembly 84: 16-bit Binary to BCD Conversion

The Challenge of Displaying Numbers Once the Z80 has calculated a final value (e.g., a score of 4296 decimal), this number is stored as a 16-bit binary value (1000010000000000B). To display it on the screen, we need to convert it into a sequence of decimal digits (4′, 2′, 9′, 6′) that can be looked up in the font table. Goal: Convert a 16-bit binary number into a 16-bit BCD value (four decimal digits). ...

September 28, 2025

Z80 Assembly 83: 16-bit BCD to Binary Conversion

The Challenge of User Input When a user types a number (e.g., 4296), it is stored as a series of ASCII characters (or often converted immediately into Binary-Coded Decimal (BCD)). The Z80 needs this number in a single 16-bit binary value for fast calculation. Goal: Convert a 16-bit BCD value (representing a number from 0 to 9999) into a 16-bit binary value. The BCD Structure A 16-bit BCD value typically uses the entire word (two bytes) to store four decimal digits (0-9). ...

September 28, 2025

Z80 Assembly 09: BCD Arithmetic and the RST (Restart) Interrupts

BCD Arithmetic: The DAA Instruction Binary-Coded Decimal (BCD) is a way to store numbers where each byte holds two decimal digits (0-9). This is vital for financial or numerical applications where decimal accuracy is required, as standard binary math can introduce rounding errors when converting to decimal. The Problem: If you add 9 and 1 in binary, the result is 10 (0A Hex). In BCD, the result should be 10 (10 Hex). ...

September 27, 2025