[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] swap bits
From: |
Theodore A. Roth |
Subject: |
Re: [avr-gcc-list] swap bits |
Date: |
Tue, 21 Jan 2003 10:00:00 -0800 (PST) |
On Tue, 21 Jan 2003, 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.
How about this? (input in r1):
ldi r0, 8
loop:
ror r1
rol r2
dec r0
brne loop
mov r1, r2 ; optional
The trick here is that the ror shifts the bits from the input into the
carry and the rol shifts the carry into output.
I don't think you can do this in a single register. If it can, I'd like to
hear from some assembly guru out there.
Ted Roth
avr-gcc-list at http://avr1.org