Reputation: 3744
The title says it all. I want to know whether an x86 instruction that reads data from memory, translates its bytes or its bits to the Little-Endian order. For example if we have the following data at address 0 (in binary) (written here in RAW format, sequential):
00110010 01010100
And we read it the following way:
mov ax, word [0]
What will AX
contain - "01010100 00110010" or "00101010 01001100"? Or translated into unsigned integer in decimal - "21554" or "10828"?
I suppose that the x86 integer instructions will interpret the register sequential binary data as a Big-Endian binary number, the same endianness as Arabic numbers are written.
Upvotes: 16
Views: 24506
Reputation: 1782
1.3.1 Bit and Byte Order x86 is little-endian. In illustrations of data structures in memory, smaller addresses appear toward the bottom of the figure; addresses increase toward the top. Bit positions are numbered from right to left. The numerical value of a set bit is equal to two raised to the power of the bit position. IA-32 processors are “little endian” machines; this means the bytes of a word are numbered starting from the least significant byte. Figure 1-1 illustrates these conventions.
The terms endian and endianness refer to the convention used to interpret the bytes making up a data word when those bytes are stored in computer memory. In computing, memory commonly stores binary data by organizing it into 8-bit units called bytes. When reading or writing a data word consisting of multiple such units, the order of the bytes stored in memory determines the interpretation of the data word.
Each byte of data in memory has its own address. Big-endian systems store the most significant byte of a word in the smallest address and the least significant byte is stored in the largest address (also see Most significant bit). Little-endian systems, in contrast, store the least significant byte in the smallest address.
The illustration to the right shows an example using the data word "0A 0B 0C 0D" (a set of 4 bytes written out using left-to-right positional, hexadecimal notation) and the four memory locations with addresses a, a+1, a+2 and a+3; then, in big-endian systems, byte 0A is stored in a, 0B in a+1, 0C in a+2 and 0D in a+3. In little-endian systems, the order is reversed with 0D stored in memory address a, 0C in a+1, 0B in a+2, and 0A in a+3.
So, as you can see endianness is always about bytes order not bits.
Upvotes: 25
Reputation: 28806
AFAIK, endianness is never a bit order, it is always a byte order, no matter for which processor.
The lowest bit is always considered to be at the "right" side and the highest at the "left" side of an integral value (be it a 1, 2, 4, or 8 byte value), so shifts or rotations to the "right" always go toward the lowest bit and to the "left" always toward the highest bit. This is independent of endianness.
The x86 is little endian, meaning that the lowest byte comes first (i.e. at the lowest address). This means that the bytes 0x01
, 0x02
, 0x03
and 0x04
, in that order, can just as well be seen as the 32 bit value 0x04030201
, two 16 bit values of 0x0201
and 0x0403
or 4 single bytes (assuming that bytes are octets, i.e. 8 bit values -- there are systems where bytes have other bit sizes, but not the x86).
Upvotes: 22
Reputation: 2642
Binary is a bit tedious, so I translated it to hex; hope that's okay.
The answer to your question, in this case, is that you will get 21,554 (in decimal).
Here is how you can ascertain this on your own...
First, place those two bytes in memory somewhere, with the Equ $
Some_16_Bit_Value Equ $
Db 032h
Db 054h
Okay, now with that in your .Data
segment, put something like this in your .Code
segment..
Mov Ax, Word Ptr [Some_16_Bit_Value] ;See what you get
The assembler will generate a complete instruction for you, like this...
mov ax,word ptr [Some_16_Bit_Value (13FE9A002h)]
Open a debug window and view that memory location (i.e., 13FE9A002h
)
There you will see the first two bytes are: 32 54
(Those are hex, which is what just about everybody uses)
Step into that mov
instruction
You will see that AX
will then contain 5432
(in hex, which is your decimal 21,554)
Upvotes: 3