Difference between revisions of "Z80 Routines:Optimized:reverseA"
From WikiTI
Buckeye Dude (Talk | contribs) (Commented the black magiks) |
Calc84maniac (Talk | contribs) |
||
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: |
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