08-19-2013, 09:37 AM
Up on WOS, someone schooled me.
This code will apparently mirror a byte as well. Still trying to get my head round the logic! (and if it works)
n=0
n A B
0 0 0 -> 0 = B
0 0 1 -> 1 = B
0 1 0 -> 0 = B
0 1 1 -> 1 = B
n=1
1 0 0 -> 0 = A
1 0 1 -> 0 = A
1 1 0 -> 1 = A
1 1 1 -> 1 = A
a XOR b and n xor b
aaaaaaaa xor bbbbbbbb and 10101010 xor bbbbbbbb = abababab
This code will apparently mirror a byte as well. Still trying to get my head round the logic! (and if it works)
Code:
;17 bytes and 66 clock cycles
Reverse:
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
n=0
n A B
0 0 0 -> 0 = B
0 0 1 -> 1 = B
0 1 0 -> 0 = B
0 1 1 -> 1 = B
n=1
1 0 0 -> 0 = A
1 0 1 -> 0 = A
1 1 0 -> 1 = A
1 1 1 -> 1 = A
a XOR b and n xor b
aaaaaaaa xor bbbbbbbb and 10101010 xor bbbbbbbb = abababab