Little-Endian是x86体系结构中的字节顺序还是位顺序? [英] Is Little-Endian a byte or bit order in x86 architecture?

查看:67
本文介绍了Little-Endian是x86体系结构中的字节顺序还是位顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.我想知道x86指令何时从内存中读取数据,是否将其字节或位转换为Little-Endian顺序.例如,如果我们在地址"0"处有以下数据(二进制)(以RAW格式,在此依次写入):

The title says it all. I want to know when a x86 instruction reads data from memory does it translates it's bytes or it's bits to the Little-Endian order. For example if we have the following data at address "0" (in binary) (written here in RAW format, sequental):

00110010 01010100

00110010 01010100

如果我通过以下方式阅读它:

And if I read it the following way:

mov ax, word [0]

"ax"将包含什么内容-"01010100 00110010"或"00101010 01001100"?还是转换成无符号整数(假设x86 intiger指令会将寄存器顺序二进制数据解释为Big-Endian二进制数,写成与阿拉伯数字相同的字节序)以十进制表示-​​ 21554"或"10828"?

What will 'ax' contain - "01010100 00110010" or "00101010 01001100"? Or translated into unsigned integer (supposing that the x86 intiger instructions will interpret the register sequential binary data as a Big-Endian binary number, the same endian as arabic numbers are written) in decimal - "21554" or "10828"?

推荐答案

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.

术语字节序"和字节序"是指当这些字节存储在计算机内存中时用于解释构成数据字的字节的约定.在计算中,内存通常通过将二进制数据组织成称为字节的8位单元来存储二进制数据.在读取或写入由多个这样的单元组成的数据字时,存储在存储器中的字节顺序决定了数据字的解释.

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.

右图显示了一个示例,该示例使用数据字"0A 0B 0C 0D"(一组四个字节,使用从左到右的位置,十六进制表示法写入)以及地址为a,a的四个存储单元+ 1,a + 2和a + 3;然后,在大端系统中,字节0A存储在a中,字节0B存储在a + 1中,0C存储在a + 2中,0D存储在a + 3中.在小端系统中,顺序相反,存储地址a中存储的0D,a + 1中的0C,a + 2中的0B和a + 3中的0A.

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.

这篇关于Little-Endian是x86体系结构中的字节顺序还是位顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆