Difference between revisions of "Z80 Routines:Optimized:reverseA"
From WikiTI
m |
Calc84maniac (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 32: | Line 32: | ||
;output: Reversed byte in A | ;output: Reversed byte in A | ||
;destroys B | ;destroys B | ||
− | ; | + | ;17 bytes and 66 clock cycles |
;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 | + | |
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 11:59, 31 August 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 ;17 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