Little-Endianness 在 x86 架构中是字节顺序还是位顺序? [英] Is Little-Endianness a byte order or a bit order in the x86 architecture?

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

问题描述

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

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

00110010 01010100

我们是这样阅读的:

mov ax, word [0]

AX 将包含什么 - 01010100 00110010"或00101010 01001100"?或者翻译成十进制的无符号整数——21554";还是10828"?
我想 x86 整数指令会将寄存器顺序二进制数据解释为 Big-Endian 二进制数,与写入阿拉伯数字的字节顺序相同.

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.

推荐答案

1.3.1 位和字节顺序x86 是小端的.在内存中的数据结构的插图中,较小的地址出现在图的底部;地址向顶部增加.位位置从右到左编号.设置位的数值等于 2 的位位置次方.IA-32 处理器是小端"机器;这意味着字节一个字从最低有效字节开始编号.图 1-1 说明了这些约定.

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.

内存中的每个字节数据都有自己的地址.Big-endian 系统将一个字的最高有效字节存储在最小地址中,而最低有效字节存储在最大地址中(另请参阅最高有效位).相比之下,小端系统将最低有效字节存储在最小地址中.

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"(使用从左到右位置的十六进制表示法写出的一组 4 个字节)和地址为 a、a 的四个内存位置的示例+1、a+2 和 a+3;然后,在大端系统中,字节 0A 存储在 a 中,0B 存储在 a+1 中,0C 存储在 a+2 中,0D 存储在 a+3 中.在little-endian系统中,顺序相反,0D存储在内存地址a中,0C存储在a+1中,0B存储在a+2中,0A存储在a+3中.

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-Endianness 在 x86 架构中是字节顺序还是位顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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