Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Little-Endianness a byte order or a bit order in the x86 architecture?

The title says it all. I want to know whether an x86 instruction that reads data from memory, translates its bytes or its bits to the Little-Endian order. For example if we have the following data at address 0 (in binary) (written here in RAW format, sequential):

00110010 01010100

And we read it the following way:

mov ax, word [0]

What will AX contain - "01010100 00110010" or "00101010 01001100"? Or translated into unsigned integer in decimal - "21554" or "10828"?
I suppose that the x86 integer instructions will interpret the register sequential binary data as a Big-Endian binary number, the same endianness as Arabic numbers are written.

like image 570
AnArrayOfFunctions Avatar asked Sep 19 '14 16:09

AnArrayOfFunctions


People also ask

Is endianness bits or bytes?

In computing, endianness is the order or sequence of bytes of a word of digital data in computer memory.

What is the endianness of x86?

The x86 processor architecture uses the little-endian format. Motorola and PowerPC processors generally use big-endian. Some architectures, such as SPARC V9 and IA64, feature switchable endianness (i.e., they are bi-endian).

What is little-endian in architecture?

Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first, at the lowest storage address. Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.

What is little-endian byte order?

Little Endian byte ordering is defined as follows: In a binary number consisting of multiple bytes (e.g., a 32-bit unsigned integer value, the Group Number, the Element Number, etc.), the least significant byte shall be encoded first; with the remaining bytes encoded in increasing order of significance.


2 Answers

AFAIK, endianness is never a bit order, it is always a byte order, no matter for which processor.

The lowest bit is always considered to be at the "right" side and the highest at the "left" side of an integral value (be it a 1, 2, 4, or 8 byte value), so shifts or rotations to the "right" always go toward the lowest bit and to the "left" always toward the highest bit. This is independent of endianness.

The x86 is little endian, meaning that the lowest byte comes first (i.e. at the lowest address). This means that the bytes 0x01, 0x02, 0x03 and 0x04, in that order, can just as well be seen as the 32 bit value 0x04030201, two 16 bit values of 0x0201 and 0x0403 or 4 single bytes (assuming that bytes are octets, i.e. 8 bit values -- there are systems where bytes have other bit sizes, but not the x86).

like image 173
Rudy Velthuis Avatar answered Oct 18 '22 18:10

Rudy Velthuis


1.3.1 Bit and Byte Order x86 is little-endian. In illustrations of data structures in memory, smaller addresses appear toward the bottom of the figure; addresses increase toward the top. Bit positions are numbered from right to left. The numerical value of a set bit is equal to two raised to the power of the bit position. IA-32 processors are “little endian” machines; this means the bytes of a word are numbered starting from the least significant byte. Figure 1-1 illustrates these conventions.

enter image description here

The terms endian and endianness refer to the convention used to interpret the bytes making up a data word when those bytes are stored in computer memory. In computing, memory commonly stores binary data by organizing it into 8-bit units called bytes. When reading or writing a data word consisting of multiple such units, the order of the bytes stored in memory determines the interpretation of the data word.

Each byte of data in memory has its own address. Big-endian systems store the most significant byte of a word in the smallest address and the least significant byte is stored in the largest address (also see Most significant bit). Little-endian systems, in contrast, store the least significant byte in the smallest address.

The illustration to the right shows an example using the data word "0A 0B 0C 0D" (a set of 4 bytes written out using left-to-right positional, hexadecimal notation) and the four memory locations with addresses a, a+1, a+2 and a+3; then, in big-endian systems, byte 0A is stored in a, 0B in a+1, 0C in a+2 and 0D in a+3. In little-endian systems, the order is reversed with 0D stored in memory address a, 0C in a+1, 0B in a+2, and 0A in a+3.

enter image description hereenter image description here

So, as you can see endianness is always about bytes order not bits.

like image 39
Ruslan Gerasimov Avatar answered Oct 18 '22 17:10

Ruslan Gerasimov