Difference between revisions of "Z80 Routines:Optimized:reverseA"
From WikiTI
m |
Buckeye Dude (Talk | contribs) (Commented the black magiks) |
||
Line 35: | Line 35: | ||
;author: calcmaniac84 | ;author: calcmaniac84 | ||
ReverseA: | ReverseA: | ||
− | ld b,a | + | ld b,a ;b=ABCDEFGH |
− | rrca | + | rrca ;a=HABCDEFG |
− | rrca | + | rrca ;a=GHABCDEF |
− | xor b | + | xor b \ and %10101010 \ xor b ;a=GBADCFEH |
− | + | ld b,a ;b=GBADCFEH | |
− | + | rrca ;a=HGBADCFE | |
− | ld b,a | + | rrca ;a=EHGBADCF |
− | rrca | + | rrca ;a=FEHGBADC |
− | rrca | + | rrca ;a=CFEHGBAD |
− | rrca | + | xor b \ and %01100110 \ xor b ;a=GFEDCBAH |
− | rrca | + | rrca ;a=HGFEDCBA</nowiki> |
− | xor b | + | |
− | + | ||
− | + | ||
− | + | ||
− | + |
Revision as of 21:11, 21 May 2011
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 ;b=ABCDEFGH rrca ;a=HABCDEFG rrca ;a=GHABCDEF xor b \ and %10101010 \ xor b ;a=GBADCFEH ld b,a ;b=GBADCFEH rrca ;a=HGBADCFE rrca ;a=EHGBADCF rrca ;a=FEHGBADC rrca ;a=CFEHGBAD xor b \ and %01100110 \ xor b ;a=GFEDCBAH rrca ;a=HGFEDCBA