我的基于 AMD 的计算机使用小端还是大端?
我正在学习计算机系统课程,并且我正在尝试确定,肯定,我的基于 AMD 的计算机是否是一台小端机器? 我相信这是因为它与英特尔兼容。
具体来说,我的处理器是 AMD 64 Athlon x2。
我知道这在 C 编程中很重要。 我正在编写 C 程序,我正在使用的方法会受到此影响。 我试图弄清楚如果我在基于 Intel 的机器上运行该程序是否会得到相同的结果(假设是小端机器)。
最后,让我问一下:是否有任何和所有能够运行 Windows(XP、Vista、2000、Server 2003 等)的计算机,例如 Ubuntu Linux 桌面 是小端字节序吗?
I'm going though a computers system course and I'm trying to establish, for sure, if my AMD based computer is a little-endian machine? I believe it is because it would be Intel-compatible.
Specifically, my processor is an AMD 64 Athlon x2.
I understand that this can matter in C programming. I'm writing C programs and a method I'm using would be affected by this. I'm trying to figure out if I'd get the same results if I ran the program on an Intel based machine (assuming that is little endian machine).
Finally, let me ask this: Would any and all machines capable of running Windows (XP, Vista, 2000, Server 2003, etc) and, say, Ubuntu Linux desktop be little endian?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
对于你的最后一个问题,答案是否定的。 Linux 能够在大端机器上运行,例如老一代的 PowerMac。
In answer to your final question, the answer is no. Linux is capable of running on big endian machines like e.g., the older generation PowerMacs.
您必须下载专为大端机器设计的 Ubuntu 版本。 我只知道 PowerPC 版本。 我确信您可以找到一些具有更通用的大端实现的地方。
You have to download a version of Ubuntu designed for big endian machines. I know only of the PowerPC versions. I'm sure you can find some place which has a more generic big-endian implementation.
则使用它
如果 LE
*macro 将调用实数函数,并且
如果 BE
*macro 将被定义为单词而不是函数,并且您的数字将在括号之间,
and use this
if LE
*macro will call real function and it will convert to BE
if BE
*macro will be defined as word not a function and your number will be between brackets
我们现在有了
std::endian
!https://en.cppreference.com/w/cpp/types/endian
We now have
std::endian
!https://en.cppreference.com/w/cpp/types/endian
所有 x86 和 x86-64 机器(只是 x86 的扩展)都是小端字节序。
您可以通过以下方式确认:
All x86 and x86-64 machines (which is just an extension to x86) are little-endian.
You can confirm it with something like this:
用 C 语言编写与字节序无关的代码
An easy way to know the endiannes is listed in the article Writing endian-independent code in C
假设你安装了 Python,你可以运行这个单行代码,它将在小端机器上打印“little”,在大端机器上打印“big”:
Assuming you have Python installed, you can run this one-liner, which will print "little" on little-endian machines and "big" on big-endian ones:
“兼容英特尔”并不是很准确。
英特尔曾经生产大端处理器,特别是 StrongARM 和 XScale。 这些不使用 IA32 ISA,通常称为 x86。
更早的历史上,Intel 还生产了小端 i860 和 i960,它们也不兼容 x86。
追溯历史,x86 的前身(8080、8008 等)也不兼容 x86。 作为8位处理器,字节序并不重要......
如今,Intel仍然制造Itanium(IA64),它是双字节序:正常操作是大字节序,但处理器也可以在小字节序模式下运行。 它确实能够以小端模式运行 x86 代码,但本机 ISA 不是 IA32。
据我所知,AMD 的所有处理器都与 x86 兼容,并具有一些扩展,例如 x86_64,因此必然是小端。
Ubuntu 可用于 x86(小端)和 x86_64(小端),ia64(大端)、ARM(el)(小端)、PA-RISC(大端)的移植不太完整,尽管处理器同时支持)、PowerPC(大端)和 SPARC(大端)。 我不相信有 ARM(eb)(大端)端口。
"Intel-compatible" isn't very precise.
Intel used to make big-endian processors, notably the StrongARM and XScale. These do not use the IA32 ISA, commonly known as x86.
Further back in history, Intel also made the little-endian i860 and i960, which are also not x86-compatible.
Further back in history, the prececessors of the x86 (8080, 8008, etc.) are not x86-compatible either. Being 8-bit processors, endianness doesn't really matter...
Nowadays, Intel still makes the Itanium (IA64), which is bi-endian: normal operation is big-endian, but the processor can also run in little-endian mode. It does happen to be able to run x86 code in little-endian mode, but the native ISA is not IA32.
To my knowledge, all of AMD's processors have been x86-compatible, with some extensions like x86_64, and thus are necessarily little-endian.
Ubuntu is available for x86 (little-endian) and x86_64 (little-endian), with less complete ports for ia64 (big-endian), ARM(el) (little-endian), PA-RISC (big-endian, though the processor supports both), PowerPC (big-endian), and SPARC (big-endian). I don't believe there is an ARM(eb) (big-endian) port.
下面的代码片段有效:
代码中的“短”整数是 0x0100(十进制 256),长度为 2 个字节。 最低有效字节是 00,最高有效字节是 01。小尾数顺序将最低有效字节放入变量的地址中。 所以它只是检查变量指针指向的地址处的字节值是否为0。
如果为0,则为小端字节序,否则为大端字节序。
The below snippet of code works:
The "short" integer in the code is 0x0100 (256 in decimal) and is 2 bytes long. The least significant byte is 00, and the most significant is 01. Little endian ordering puts the least significant byte in the address of the variable. So it just checks whether the value of the byte at the address pointed by the variable's pointer is 0 or not.
If it is 0, it is little endian byte ordering, otherwise it's big endian.