| ??? 04/09/03 09:18 Read: times |
#43111 - RE: how to swap the bit in C Responding to: ???'s previous message |
Michael,
I do agree that swapping bits in C is less econimical than doing it in assembly; the code I presented was not intended to be as economical as possible, it was merely intended as to demonstrate how it could be done using less RAM memory. Using a look-up table may not always be possible, especially in the smaller controllers. Here's a somewhat more economical piece of code in assembly (16 bytes): ;R0 holds the byte to be manipulated. ;Result is returned in R1 swap_bits: mov R2,#9 nxt_shift: djnz R2,shift jmp end_shift shift: mov A,R0 rrc A mov R0,A mov A,R1 rlc A mov R1,A jmp nxt_shift end_shift: ret |



