且构网

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

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

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

简短的答案是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年代中期,始于Intel的第一个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汇编语言仍然可以使用addlsublandlorl,...等指令在32位寄存器上执行算术运算,其中l表示"long" ",即4字节/32位.使用addqsubqandqorq,...等完成64位伪指令,其中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.

编辑:

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