[fpc-pascal] Reversing bit-order of byte
Koenraad Lelong
fpascal at brouwerij.homelinux.net
Fri May 4 08:13:47 CEST 2012
On 03-05-12 13:27, Thomas Schatzl wrote:
...
> function reverse(b : byte) : byte; assembler; nostackframe;
> asm
> rbit r0, r0
> // rbit reverses the whole word, so now you have
> // your value in bits 31-24... so shift right by that amount
> // should fix this up (bits 23-0 contain junk, we shift that out
> // anyway)
> lsr r0, r0, #24
> end;
>
> However, this may not compile because fpc may not recognize the rbit
> instruction.
>
> Following is a version that encodes the instruction directly, retrieved
> from disassembling some gcc code:
>
> function reverse(b : byte) : byte; assembler; nostackframe;
> asm
> .long 0xe6ff0f30 // rbit r0, r0
> lsr r0, r0, #24
> end;
>
Thanks guys, I'll try and test this weekend.
Regards,
Koenraad Lelong.
More information about the fpc-pascal
mailing list