且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么 32 位应用程序可以在 64 位 x86 CPU 上运行?

更新时间:2023-10-16 16:23:22

简短的回答是 x86 系列处理器都被设计为向后兼容.在新 CPU 中执行算术和读/写操作的逻辑电路仍然能够执行为旧 CPU 设计的指令,同时还能够执行诸如 64 位加减法等较新的指令.

The short answer is that the x86 family of processors were all designed to be backward compatible. The logic circuits that perform arithmetic and read/write operations in new CPUs are still capable of carrying out instructions designed for older CPUs while also carrying out newer instructions like 64-bit add and subtract.

如果你想了解更多历史......

If you want more history...

x86 指令集可以追溯到 1970 年代中期,从英特尔的第一个 16 位处理器 8086.此 CPU 上的通用 16 位(2 字节)寄存器称为 AXBXCXDX代码>.8086 还允许访问每个寄存器的高字节和低字节.例如,您可以使用名称 AL 访问 AX 的低 8 位,或使用 AH 访问高 8 位.

The x86 instruction set dates back to the mid-1970s, beginning with Intel's first 16-bit processor, the 8086. The general-purpose 16-bit (2-byte) registers on this CPU were called AX, BX, CX, and DX. The 8086 also allowed access to the high and low bytes of each register. For example, you could access the lower 8 bits of AX using the name AL, or the higher 8 bits using AH.

当英特尔开始开发具有新功能的新处理器时,他们希望它们能够向后兼容 8086 以及随后出现的任何处理器.紧随其后的是 80186、80286 和 80386——最后一个是他们的第一个 32 位处理器.

When Intel started developing new processors with new features, they wanted them to be backward compatible with the 8086 and any processors that came afterward. Next in line came the 80186, the 80286, and the 80386--the last of which was their first 32-bit processor.

当然,80386 上的所有寄存器都必须是 32 位的,但它还必须向后兼容旧的 x86 处理器.因此,英特尔没有替换寄存器,而是将现有的寄存器扩展到 EAXEBXECX 等.(E 意思是扩展").AX 寄存器只是 EAX 寄存器的低 16 位,仍然可以访问.

Of course, all the registers on the 80386 had to be 32-bit, but it also had to be backward compatible with older x86 processors. So rather than replace the registers, Intel merely extended the existing ones to EAX, EBX, ECX, ...etc. (E meaning "extended"). The AX register is merely the lower 16 bits of theEAXregister, and is still accessible.

英特尔的第一个 64 位处理器也遵循同样的逻辑;32 位 EAX 被扩展为 64 位 RAX 等等.当前的 x86-64 汇编语言仍然可以使用 addlsublandl 等指令对 32 位寄存器执行算术运算orl, ... 等,其中 l 代表long",即 4 字节/32 位.64 位算法是用 addqsubqandqorq、...等完成的,用 q代表四字",即8字节/64位.

The same logic was followed with Intel's first 64-bit processor; the 32-bit EAX was extended to the 64-bit RAX and so on. The current x86-64 assembly language can still perform arithmetic operations on 32-bit registers using instructions like addl, subl, andl, orl, ... etc, with the l standing for "long", which is 4 bytes/32 bits. 64-bit arthimetic is done with addq, subq, andq, orq, ...etc, with q standing for "quadword", which is 8 bytes/64 bits.

编辑:这个 pdf 看起来很好地介绍了 32 位和 64 位 x86 架构之间的差异.

EDIT: This pdf looks like it gives a good introduction to the differences between 32-bit and 64-bit x86 architectures.