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

编程入门 行业动态 更新时间:2024-10-28 04:29:44
本文介绍了为什么 32 位应用程序可以在 64 位 x86 CPU 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

32 位应用程序可执行文件包含 32 位 CPU 的机器代码,但是 32 位和 64 位 Intel CPU 的程序集和内部架构(寄存器数量、寄存器宽度、调用约定)不同,所以如何32 位 exe 在 64 位机器上运行?

32-bit application executables contain machine code for a 32-bit CPU, but the assembly and internal architecture (number of registers, register width, calling convention) of 32-bit and 64-bit Intel CPU's differ, so how can a 32-bit exe run on a 64-bit machine?

维基百科的 x86-64 文章说:

x86-64 完全向后兼容 16 位和 32 位 x86 代码.因为完整的 x86 16 位和 32 位指令集仍然在硬件中实现而没有任何干预模拟,现有 x86 可执行文件在运行时不会产生兼容性或性能损失,而现有应用程序经过重新编码以利用处理器设计的新功能可能会实现性能提升.

x86-64 is fully backwards compatible with 16-bit and 32-bit x86 code. Because the full x86 16-bit and 32-bit instruction sets remain implemented in hardware without any intervening emulation, existing x86 executables run with no compatibility or performance penalties, whereas existing applications that are recoded to take advantage of new features of the processor design may achieve performance improvements.

我不明白他们所说的保持在硬件中实现而没有任何干预仿真是什么意思.什么意思?

I don't understand what they mean by saying remain implemented in hardware without any intervening emulation. What does it mean?

推荐答案

简短的回答是 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 字节)寄存器称为 AX、BX、CX 和 DX.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 处理器.因此,英特尔没有替换寄存器,而是将现有的寄存器扩展到 EAX、EBX、ECX 等.(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 汇编语言仍然可以使用 addl、subl、andl、 等指令对 32 位寄存器执行算术运算orl, ... 等,其中 l 代表long",即 4 字节/32 位.64 位算法是用 addq、subq、andq、orq、...等完成的,用 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.

更多推荐

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

本文发布于:2023-11-04 17:21:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   CPU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!