Z80 Routines:Optimized:reverseA

From WikiTI
Revision as of 14:15, 26 October 2009 by Galandros (Talk | contribs)

Jump to: navigation, search

This is a faster/smaller (and also obfuscated) replacement for the normal reverse a.

Typical routine:

;input: b
;output: a
;25 bytes, 96 clock cycles
typicalreversea:
	rr b
	rla
	rr b
	rla
	rr b
	rla
	rr b
	rla
	rr b
	rla
	rr b
	rla
	rr b
	rla
	rr b
	rla
	ret

Better routine:

;- Reverse a
;input:	byte in A
;output: Reversed byte in A
;destroys B
;18 bytes and 66 clock cycles
;author: calcmaniac84
ReverseA:
	ld b,a
	rrca
	rrca
	xor b
	and %10101010
	xor b
	ld b,a
	rrca
	rrca
	rrca
	rrca
	xor b
	and %01100110
	xor b
	rrca
	ret