Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Memory/Storage
 
 
Memory/Storage  

Does endianness matter?

Posted: 06 Nov 2015     Print Version  Bookmark and Share

Keywords:embedded systems  LED indicator  graphical display  RAM  RTOS 

For most programmers, details of computer architecture are of no interest or significance. Even embedded developers, who normally do concern themselves with details, when programming in a high level language, ignore matters like cache configuration. Factors like memory location and size do matter, when looking at the project as a whole, but even these parameters do not influence day to day coding. The order in which bytes are stored in a word—the endianness—of the CPU in use can often also be ignored. However, once in a while, an appreciation of this matter is critical. The same consideration applies to transmission of data; what order are bytes sent down a serial line or over a network? This article reviews exactly what endianness means and how it affects embedded software.

What is endianness?
In almost all modern embedded systems, memory is organized into bytes. CPUs, however, process data as 8-, 16- or 32-bit words. As soon as this word size is larger than a byte, a decision needs to be made with regard to how the bytes in a word are stored in memory. There are two obvious options and a number of other variations. The property that describes this byte ordering is called "endianness" (or, sometimes, "endianity").

Broadly speaking, the endianness in use is determined by the CPU. Because there are a number of options, it is unsurprising that different semiconductor vendors have chosen different endianness for their CPUs. The questions, from an embedded software engineer's perspective, are "Does endianness matter?" and "If so, how much?".

There are broadly two circumstances when a software developer needs to think about endianness:

 • data transmitted over a communications link or network
 • data handled in multiple representations in software

The former situation is quite straightforward – it is simply a matter of following or defining a protocol. TCP/IP, for example, does not specify the byte order, but big-endian is the convention. This means that the 32-bit value 0x12345678 would be sent as the sequence 0x12, 0x34, 0x56, 0x78.

The latter is trickier and requires some thought.

Endianness in CPUs
First of all, we need to provide some boundaries for this discussion. Only 32-bit CPUs will be considered, but the same issues apply to 16- and 64-bit devices. Even 8-bit devices typically have instructions that deal with larger data units. The consideration is also limited to the obvious endianness options: least significant byte stored at lowest address ("little-endian") and most significant byte stored at lowest address ("big-endian"). These two options may be visualized quite easily:


1 • 2 Next Page Last Page



Comment on "Does endianness matter?"
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top