-
Notifications
You must be signed in to change notification settings - Fork 4
Endianness
In computing endianness is the byte order of a primitive data type longer than 1 byte. There are 2 types of endiannesses: Little-endian and big-endian. Big-endian has bytes ordered from the most significant one to the least significant one which matches our every-day reading order. Little-endian means that bytes are ordered from the least significant one to the most significant one. The term endian is a bit misleading since it describes the starting byte of a value. You may imagine the terms as little-/big-startian instead.
The little-endian byte order is most commonly used. Its Advantage is that at the address of a (for instance) 64-bit value the lower 32 bits can be accessed as well as the lowest 16, and 8 bits. The disadvantage is that it makes hacking and debugging a little bit more difficult since we are used to read from left to right. Especially since nibbles (4 bits of a byte) are still read from left to right in a hex byte. So it's a mix of two reading directions.
0x01234567 is the following in little-endian: 0x67452301
List of little-endian systems: NES, SNES, Nintendo Switch, GameBoy, GameBoy Color, VirtualBoy, GBA, DS, 3DS, PS1, PS2, PS4, PS5, PSP, PS Vita, XBOX, XBOX 360, XBOX One, XBOX Series, Master System, Dreamcast, GameGear, x86, x64
Some systems make use of the big-endian byte order instead. Bytes are stored from left to right which matches our reading direction. This makes hacking and debugging a little bit easier. However, accessing a byte of a (for instance) 32-bit value requires incrementing the address or additional operations on the register. Single bytes are often stored in a 32-bit field wasting 3 bytes.
Single bytes stored as 32-bit integers in a big-endian PowerPC-based program wasting 3 bytes.
The byte is loaded as a 32-bit integer (lwz: Load Word and Zero), and then processed as a single byte (stb: store byte).
List of big-endian systems: N64, GameCube, Triforce Arcade System, Wii, Wii U, PS3, Mega Drive, 32X, Mega-CD, Sega Saturn
Sometimes you will find data stored in the opposite endianness of a system's own architecture. This may be because a loaded file or data is encoded in a certain endianness.
Some emulators that emulate a system of the opposite endianness than it's own architecture map the emulated memory in 16- or 32-bit chunks of its native endianness. For instance, Project64 running on a little-endian x64 or x86 machine stores the N64 big-endian ROM and RAM in 32-bit little-endian chunks. This makes viewing and hacking N64 games running on Project64 significantly harder, especially if some value is stored across 2 or even more of these 32-bit chunks. However, MungPlex is able to re-reorder these regions and handling them will feel like dealing with normal big-endian data.