hi all, i acquired a piece of code from a website which reverses a byte of code and i am having a little trouble understanding it. could anyone explain to me why he is swapf x,w in the first line, the xorwf x,w in the second line? in my (very shallow) understanding, wouldn't what just return the code back to its original form?
thank you
(i tried to format the code as good as possible)
thomas
; input X = abcdefgh , Output X = hgfedcba
; Written by Dmitry A. Kiryashov 2000
; 12 clocks/words
(x >> 1) = 00110101
AND with 01010101 (0x55)
result: 00010101
(x << 1) = 11010110
AND with 10101010 (0xAA)
result: 10000010
OR the results: 10010111
Step 2)
(x >> 2) = 00100101
AND with 00110011 (0x33)
result: 00100001
(x << 2) = 01011100
AND with 11001100 (0xCC)
result: 01001100
OR the results: 01101101
Step 3)
(x >> 4) = 00000110
AND with 00001111 (0x0F)
result: 00000110
(x << 4) = 11010000
AND with 11110000 (0xF0)
result: 11010000
OR the results: 11010110
Compare that to the original and you will see the bits have been reversed. The same logic applies to the 16 bit swap. The assembly code you've listed is doing the same thing.