Category:Z80 Assembly: Difference between revisions

Line 85:
SLA A
SLA A
SLA A ;8 bytes, 32 cycles total
 
AND %00001111
Line 91:
RLCA
RLCA
RLCA ;6 bytes, 23 cycles total</lang>
 
Not only is the second method shorter, it's also faster. The accumulator-specific bit rotates take 1 byte and 4 clock cycles each. They are different, however, because unlike the two-byte versions, these <i>do not affect the zero flag.</i> This isn't a big deal, however, as more often than not if you're rotating the accumulator you're not expecting to get zero as the output anyway. If you want to know zero or not, then replace the AND %00001111 at the beginning by AND %11110000 after the 4 RLCAs.
 
Correction: The AND <i>does</i> affect the Z flag. So the end result will be the same, right?
 
If you want to know zero or not, you could also use this:
 
<lang z80>RLCA
RLCA
RLCA
RLCA
AND %11110000 ;6 bytes, 23 cycles total</lang>
 
For 16-bit bit shifting, use A instead of the other half of the register pair for faster results (unless you're checking for equality to zero, or you need the accumulator for something else.)