Difference between revisions of "Z80 Routines:Optimized:reverseA"

From WikiTI
Jump to: navigation, search
(New page: reverseA reverseA reverseA This is a faster/smaller (and also obfuscated) replacement for t...)
(No difference)

Revision as of 14:47, 26 October 2009


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