<
jimmyjo...@nospicedham.yahoo.com> wrote in message
news:0d32bddf-b6a0-4124...@l29g2000yqf.googlegroups.com...
The ordering for integers with x86 assemblers is usually the same:
mov eax, 0FFEEDDCCh
B8CCDDEEFF ; MASM
B8CCDDEEFF ; NASM
The ordering for strings with x86 assemblers is assembler dependent:
mov eax, 'ABCD'
B844434241 ; MASM
B841424344 ; NASM
I.e., you were probably using MASM ...
The difference between big-endian and little-endian is how the data is
ordered when read into a register from memory. Little-endian, like x86,
will place the first read byte into the LSB and the last read byte into the
MSB. You can see this above with the 0FFEEDDCCh value. It's stored in
reverse of the way an integer written. CC is read first. FF is read last.
Big-endian will place the first read byte into the MSB and the last read
byte into the LSB. I.e., it'll match the way an integer is written. FF
will be read first. CC will be read last. The reading order didn't change.
The byte order changed: FFEEDDCC. Basically, little-endian reverses the
memory byte order when reading from memory to register.
Put out four fingers. That's how four bytes of data is stored in memory.
Now, flip your hand over. That's what x86 (little-endian) does when
reading. For big-endian, your hand doesn't flip.
Little-endian is more efficient with integer offsets encoded into
instructions. This helps the microprocessor. Big-endian is more efficient
with string encodings. This helps you. I.e., if you read part of a string
which was stored as bytes on x86 in memory using an integer larger than a
byte in size, the characters will be reversed. E.g., if 'A' and 'B' and 'C'
and 'D' are stored as bytes on x86, reading a word starting at 'A' will
return 'BA', dword will be 'DCBA'. On a big-endian matchine, if you do the
same, you'll get 'AB' and 'ABCD' respectively. Frequently, you'll see C
code written for big-endian machines make use of integer types other than
CHAR, e.g., UNSIGNED LONG. This is to make strings faster by using larger
integer sizes. Such code won't work on x86 without reversing the byte order
of each integer.
Rod Pemberton