Z80 Routines:Optimized:reverseA

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

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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