[fpc-pascal] Reversing bit-order of byte

Thomas Schatzl tom_at_work at gmx.at
Thu May 3 10:12:43 CEST 2012


Hi,

On Thu, 2012-05-03 at 07:55 +0000, Mark Morgan Lloyd wrote:
> Koenraad Lelong wrote:
> > Hi,
> > 
> > I'm porting a driver, originally written in C, for an LCD to be used 
> > with an embedded arm-processor (STM32).
> > The original driver uses SPI, my driver will use a USART in synchronous 
> > mode because the STM32 has no SPI for 9-bit. Unfortunately, the 
> > bit-order is reversed between SPI and USART transmission.
> > Does anyone knows an efficient way to reverse bit-order of a byte for 
> > the arm-processor ? I'm going to look into the assembly language of the 
> > arm-processor, but maybe someone knows this immediately.
> > For old processors like 8085 or Z80 I know how to do this, but 
> > arm-assembler is new to me.

E.g. see

http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv

(which, in addition to the above way also gives other examples; then
there is http://www.tekpool.com/node/208 which shows even more of them
if you do not like 64 bit math)

> 
> I think I'd use a lookup table (making sure it's cacheable), 
> particularly since what you're doing is going to be called frequently 
> and you're likely to have much more than 64K memory.
> 

... however I guess that a precomputed table is likely best for your
application.

Thomas





More information about the fpc-pascal mailing list