The different instructions execute at different speeds. For example, XORing a number with itself produces 0. Well, the XOR operation
is faster than the loading operation, so many programmers use it to load a register with zero. For example, the code
movl $0, %eax
is often replaced by
xorl %eax, %eax
In octal, each digit represented three bits. In hexadecimal, each digit represents four bits. Every two digits is a full byte, and
eight digits is a 32-bit word.
One thing that confuses many people when dealing with bits and bytes on a low level is that, when bytes are written from registers
to memory, their bytes are written out least-significant-portion-first. What most people expect is that if they have a word in a register,
say 0x5d 23 ef ee(the spacing is so you can see where the bytes are), the bytes will be written to memory in that order. However, on x86
processors, the bytes are actually written in reverse order. In memory the bytes would be 0x ee ef 23 5d on x86 processors. The bytes are
written in reverse order from what they would appear conceptually, but the bits within the bytes are ordered normally.
Not all processors behave this way. The x86 processor is a little-endian processor, which means that it stores the "little end", or
least-significant byte of its words first.
Other processors are big-endian processors, which means that they store the "big end", or most significant byte, of their words first,
the way we would naturally read a number.
The byte-switching magic happens automatically behind the scenes during register-to-memorytransfers. However, the byte order can cause
problems in several instances:
* If you try to read in several bytes at a time using "movl" but deal with them on a byte-by-byte basis using the least significant byte
(i.e.-by using %al and/or shifting of the register), this will be in a different order than they appear in memory.
* If you read or write files written for different architectures, you may have to account for whatever order they write their bytes in.
* If you read or write to network sockets, you may have to account for a different byte order in the protocol.