If I write the following
section .data
align 4
X: db 1
Y: dw 5
Z: db 0x11
section .text
add dword [X], 0xAA000101
I'm trying to understand the differences between the big endian and the little endian representations, and I don't understand what will be the value of each variable for each representation? Will they be the same?
Have a look at these pictures:
This is the list of endiannesses for all architectures/instruction sets
In a big-endian configuration, the most significant byte of a doubleword (32-bits on x86) is stored in the smallest address, and the least significant byte is stored in the largest address.
In a little-endian configuration, the least significant byte is stored in the smallest address.
Let's take the big-endian example first:
If we lay out your variables in memory in a big-endian configuration we get:
or, grouped together:
When viewed as a 32-bit value that equals
0x01000511
. Adding0x01000511
and0xAA000101
gives us0xAB000612
. If we view the individual bytes in memory again we get:So the result is:
In a little-endian configuration we would have:
or, grouped together:
Viewed as a 32-bit value that equals
0x11000501
. Adding0xAA000101
gives us0xBB000602
. And when we view the individual bytes we get:With the result:
(Note: all x86 processors, AFAIK, are little-endian)