Z80 Assembly 87: 16-bit Comparison (Greater Than, Less Than, Equal)

The Need for 16-bit Comparison The Z80 has a dedicated CP R&prime; (Compare) instruction, but it only works on 8-bit values. When dealing with addresses, large scores, or multi-byte numbers, you need a robust routine to compare two 16-bit pairs, such as HL′ against `DE′. Goal: Compare HL with DE and set the flags (Zero, Carry) to indicate if HL &equals; DE&prime;, HL < DE′, or `HL > DE′. The Comparison Strategy: Subtraction The fastest way to compare two numbers is to subtract one from the other. ...

September 28, 2025