facemanfacey
New Member
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
reverse8bit:
swapf X,W ;efghabcd
xorwf X,W ;efghabcd
;abcdefgh
andlw 0x66 ;.fg..bc.
;.bc..fg.
xorwf X,F ;afgdebch
;
rrf X,W
rrf X,F ;hafgdebc
;
andlw 0x55 ;.a.g.e.c
addwf X,F ;h.f.d.b.
;a.g.e.c.
rrf X,F ;.h.f.d.b
;.a.g.e.c
addwf X,F ;ahgfedcb
;
rlf X,W
rlf X,F ;hgfedcba
;it can be replaced
;with rlf X,W
;if necessary...
Total Program instructions: 7 + 19 Total instructions executed: 13
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
reverse8bit:
swapf X,W ;efghabcd
xorwf X,W ;efghabcd
;abcdefgh
andlw 0x66 ;.fg..bc.
;.bc..fg.
xorwf X,F ;afgdebch
;
rrf X,W
rrf X,F ;hafgdebc
;
andlw 0x55 ;.a.g.e.c
addwf X,F ;h.f.d.b.
;a.g.e.c.
rrf X,F ;.h.f.d.b
;.a.g.e.c
addwf X,F ;ahgfedcb
;
rlf X,W
rlf X,F ;hgfedcba
;it can be replaced
;with rlf X,W
;if necessary...
Total Program instructions: 7 + 19 Total instructions executed: 13