Reputation: 75
What would the value in EAX be after the performing movl 100, %eax?
If the machine is little Endian? (my friend's answer)
0x00 0x00 0x00 0x11
What I think:
0x44332211? Also, does those 0x matter or can I just do one like this?
For Big Endian: (friend's answer)
0x11 0x00 0x00 0x00
Here too, I think its:
0x11223344
Upvotes: 0
Views: 761
Reputation: 61949
eax
is an x86 register, so we are talking about an x86 architecture, which is little-endian.
For the benefit of readers from all walks of life, let me also mention that the instruction movl 100, %eax
is in AT&T/GNU Assembly syntax, and it means "move 4 bytes starting at memory address 100 into register EAX". In Intel/Microsoft/Borland syntax this same instruction would be mov eax, [100]
(give or take a DWORD PTR, perhaps.)
Loading a 32-bit register from a memory location that contains the bytes 0x11, 0x22, 0x33, 0x44 on a little-endian architecture will result in that register having the value 0x44332211
. That's what little endian means: the counter-intuitive way.
Little endianness exists because it has one little (borderline) technical advantage over big-endian: if you know that the value stored at a certain memory location is small enough to fit in a smaller register, then you can read from that exact same memory location into the smaller register, and you will still get the right value. In other words:
If you load EAX with 0x00002211, and store that into the four bytes at memory location 100, then later you can load just the AX register from memory location 100, and you will get 0x2211. Contrast this with big endian, where in order to load that value into a smaller register you would have to make sure to skip the first two bytes, and start reading from memory location 102.
Intel decided to go with little endianness for the x86 architecture, despite the fact that its advantage over big endianness is minuscule, because according to engineering tradition, when we have to make a choice between two options where everything else seems equal, we tend to prefer the option that has even the slightest technical advantage over the other. Historically, anything related to human intuition and human cultural factors is completely disregarded as a possible advantage because it is not a technical advantage. The fact that we find big-endian more intuitive is because in the western world, we read and write from left-to-right, and we write numbers starting with the largest digit first, but both of these two facts are nothing but cultural accidents.
Upvotes: 7