[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] swap bits
From: |
Klaus Rudolph |
Subject: |
Re: [avr-gcc-list] swap bits |
Date: |
Tue, 21 Jan 2003 18:17:50 +0100 |
Torsten Hahn wrote:
>
> Hi,
>
> iam looking for a way, to efficiently swap all bits in an register. Can
> somebody help me with a little asm-macro or a pice of efficient c-code ?
> It schould take an 8bit value as input an give back an value, where bi7
> of the input is now the bit 0, bit6 is bit1 etc.
>
> I have no idea how to to this very well.
>
reverse_register_16:
push r17 2 cycles (internal ram)
push r18 2 cycles (internal ram)
Now
R16 value to transfer
R17 result
R18 counter
ldi r18, 0x08 1 cycle
loop:
ror r16 8 cycles
rol r17 8 cycles
dec r18 8 cycles
brne loop 17 cycles
mov r16, r17 1 cycle
pop r18 2 cycles (internal ram)
pop r17 2 cycles (internal ram)
51 cycles total without wasting any register.
10 words flash.
51 cycles is very expensive. Any better ideas here :-)
Best asm contest is open now....
Bye
Klaus
avr-gcc-list at http://avr1.org