I use a Intel processor to write this text, and this processor is is using Little Endian for the byte order. This is about Endian, not Indian :-).
Many processors I have programmed were Big Endians. With the addition of Freescale Kinetis (an ARM Cortex M4) and DSC in MCU10.2, I have a daily mixture with Big Endian (S08, ColdFire, …) and Little Endian (DSC and Kinetis).
The term “endian” is described nicely in the IEN 137 written 1980 by Danny Cohen:
“ON HOLY WARS AND A PLEA FOR PEACE“.
And the ‘war’ still seems to rage on: not only between the silicon designers, but as well between the software geeks. Standardization is a good thing, but sometimes there might not be a single way to do things: as you can break an egg from the ‘big’ or from the ‘little’ end. Well, as long as you know what you are doing and the consequences of it, that will be fine. And it keeps our world interesting ;-). One interesting thing is that some processors allow switching the endianess, PowerPC as an example.
I admit: In my mindset I feel I’m more attached to the big endian view of the world. But it is just a view. The good thing is: eclipse can view it from both sides (with a view :-)) as outlined in Memory is Everything, using the Memory Browser view:
Eclipse and MCU10 does a good job hiding the endianess from the user. Still, there are places where you can see what is behind: If you open the Project Explorer View and inspect the binary file, you will see either a ‘be’ for Big Endian or ‘le’ for Little Endian.
The ‘be’ or ‘le’ information in the Project Explorer view comes from an attribute in the ELF file which tells the reader if the architecture is either little or big endian.
From the software side I try not to think about the endianess. But it is a reality, and writing code portable between the two views (or implementation) of the world is truly challenging.
Happy egg breaking 🙂
Pingback: Extended Driver for the MMA8451Q Accelerometer | MCU on Eclipse
Hello Erich, how about the Cortex M0+? Is there some way to use big endian? little endian is by default.
LikeLike
Hi Carlos,
some for Cortex-M0+. Freescale has decided only to support Little Endian with their ARM cores. No way to switch the core to Big Endian. What I did is I updated my software to be ‘endianess’ smart, and using different code depending if the processor is little or bit endian.
LikeLike
Great! thanks. I’m going to do that too. How can I ask the compiler to tell me the endianess for the #if #else conditions?
LikeLike
You could use the followign define generated in CPU.h by Processor Expert:
#define CPU_LITTLE_ENDIAN /* The selected cpu uses little endian */
Otherwise it is very compiler dependant, see
http://sourceforge.net/p/predef/wiki/Architectures/
LikeLike
Pingback: RNet Stack for 8bit MC9S08QE128 Microcontroller and MC13201 Transceiver | MCU on Eclipse
And then one day you create a typedef to handle RGB colors using unions and you notice that the Alpha channel is used instead of Red and the Red instead of alpha.
I love that it is very simple to check if your processor uses BE or LE
LikeLike
static inline bool host_is_be(void)
{
const uint16_t check = 1;
if ( ((uint8_t *) (&check))[1] == 1)
return true;
return false;
}
LikeLike
very nice, thanks for sharing that example to find out the endianess!
LikeLike