User:New16

From OSDev.wiki
Revision as of 09:31, 23 July 2016 by osdev>New16
Jump to navigation Jump to search

Endianness refers to the order in which bytes of a multi-byte structure are placed to main memory (RAM). The bit order in any byte is normally from bit seven downto bit zero and remains preserved.

Big- vs. little-endian

In big-endian the most-significant (left-hand) byte, in little-endian the least-significant (right-hand) byte is stored at the lowest address.

Memory
address
n n+1 n+2 ...
Value
0x15
Big-endian: 0x15 - - -
Little-endian: 0x15 - - -
Value
0x0A15
Big-endian: 0x0A 0x15 - -
Little-endian: 0x15 0x0A - -
Value
0x780A15
Big-endian: 0x78 0x0A 0x15 -
Little-endian: 0x15 0x0A 0x78 -
a.s.o.

Little-endian may seem unlogical until you consider that a variable can be used more easily as both 8-bit, 16-bit, 32-bit or even 64-bit without changing its base address. Therefor AMD and Intel use little-endian order.

Example

Let's assume a x86-computer, which means little-endian order. Register eax contains the value 0xCAFEF00D. You store this register at address 0.

Common CPUs

CPU Endianness
x86 little
x86-64 little
MIPS both
Motorola big
68k big
PowerPC both