I find it amazing that there's an instruction
set even more annoying than
the 8086 (segments and all). I was amazed at the lopsidedness of the
instruction set. I'm beginning to think I was lucky in skipping this
particular chip (my first 8-bit was the 6809, so I think I got spoiled).
Classic 8 bit chips are all about the quirks. In the case of the Z80,
the main quirk is that it's an 8080 hiding behind an assembly language
designed to lure you into thinking it's orthogonal. Optimizations of
these processors are all about knowing the quirks and your algorithm.
Since 10 fits into a single byte, when calculating the remainder, you
only need to calculate the lower byte. You know that r+6 is also
always going to fit into 1 byte, so you can drop the 16 bit math in
that case, too. If you stick with the 0-799 limit originally
discussed, you know that the quotient is a one byte quantity with zero
in the upper two bits, which may allow for further optimization. q
+ ((r + 6) >> 4) will always be less than 128. In this case q + ( r >
9 ) is probably faster anyway, even if you allow for the full range.