I\'m in a microprocessors class and we are using assembly language in Freescale CodeWarrior to program a 68HCS12 micro controller. Our assignment this week is to revers a by
I had also to program this bit reverse for the university (for 8 bits). Here is how I did:
MOV AL, 10001011B ;set the value to test
MOV CL, 7
MOV DH, 1
MOV DL, 0
loop1: PUSH AX
AND AL, DH
PUSH CX
MOV CL, DL
SHR AL, CL
POP CX
MOV BH, AL
SHL BH,CL
OR CH,BH
DEC CL
INC DL
SHL DH, 1
POP AX
CMP DL, 8
JE END
JMP LOOP1
END:
I didn't commented it so here is how it works:
DH is a 1 which travels in the byte like first time: 00000001; second time 00000010and so on. When you make an AND with the AL you get 0 or something like 100or 10000 you have to shift that to the right to get it as 0 or 1.
Then, put it in BH and shift to the desired position which is 7for byte 0, 6for byte 1and so on. Then OR to our final result and INC and DEC what is necessary. Do not forget the conditional jumps and to pop AX for the next loop :)
Result will be in CH.