[fpc-pascal] Reversing bit-order of byte

David Butler djbutler at gmail.com
Thu May 3 10:50:29 CEST 2012

If you want to go assembly:

function ReverseBits(const Value: LongWord): LongWord; register; assembler;
      BSWAP   EAX
      MOV     EDX, EAX
      AND     EAX, 0AAAAAAAAh
      SHR     EAX, 1
      AND     EDX, 055555555h
      SHL     EDX, 1
      OR      EAX, EDX
      MOV     EDX, EAX
      AND     EAX, 0CCCCCCCCh
      SHR     EAX, 2
      AND     EDX, 033333333h
      SHL     EDX, 2
      OR      EAX, EDX
      MOV     EDX, EAX
      AND     EAX, 0F0F0F0F0h
      SHR     EAX, 4
      AND     EDX, 00F0F0F0Fh
      SHL     EDX, 4
      OR      EAX, EDX

On Thu, May 3, 2012 at 9:10 AM, Koenraad Lelong <
fpascal at brouwerij.homelinux.net> 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.
> Thanks for any hints.
> Koenraad Lelong.
> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120503/cac3e355/attachment.html>

More information about the fpc-pascal mailing list