[fpc-pascal] Byte order modification in fpc on ARM?

Michael Van Canneyt michael at freepascal.org
Mon Oct 19 15:30:36 CEST 2015



On Mon, 19 Oct 2015, Bo Berglund wrote:

> I am making a control program for a data collection system using FPC +
> Lazarus on a Raspberry Pi2 platform. I will use a number of Delphi
> units, which implement the communications and data handling needs in a
> way that works fine on a Windows platform.
>
> While looking over existing code I see that there are instructions to
> modify received data from the instrument by reversing the byte order.
> The reason for that was that the instrument is based on a Motorola
> controller and it uses the opposite byte order as in the Intel CPU:s
> on the PC. Since download is of binary data areas in the instrument
> the byte order change was necessary for all multi-byte data like word
> and integers as well as real (floating point 32 bit values).
>
> Now I wonder if it will be necessary also on an ARM platform like the
> RPi2?
> Is there a function or such to interrogate the byte order of the
> platform FPC runs on? So that I could add a test at the start of
> download to check if swapping is needed?

There are compiler defines defines that give you the endianness.
{$IFDEF ENDIAN_BIG}
{$IFDEF ENDIAN_LITTLE}

And
{$IFDEF FPC_LITTLE_ENDIAN}
{$IFDEF FPC_BIG_ENDIAN}

Then there are BeToN, LeTon and and other functions that force a certain endianness or convert from a certain endianness to native endianness.

Michael.



More information about the fpc-pascal mailing list