AMD64 在 i586 上运行还是反之亦然?
我有一个小型 C 程序,我希望将其从 Linux 移植到 Windows。我可以使用 MinGW 编译器来完成此操作,并且我注意到它有两个不同的前缀:amd64 和 i586。我在一台 i686 计算机上,我想知道如果我使用 amd64 架构编译我的 C 程序,它会在我的 i686 计算机上运行吗?反之亦然?
更新:
是否有编译器可以编译 C 代码以在任何体系结构上运行?
I have a small C program that I wish to port from Linux to Windows. I can do this with the MinGW compiler, and I have noticed that it has two different prefixes, amd64 and i586. I am on an i686 computer and I was wondering if I compile my C program using and amd64 architecture, will it run on my i686 machine? And vice-versa?
UPDATE:
Is there a compiler that compile C code to run on ANY architecture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您为 i586(实际上通常称为 x86)编译代码,它应该可以在 AMD64 (x86-64) 处理器上正常工作,因为只要操作系统支持此功能,x86-64 处理器就可以执行“旧版”32 位代码 -主流操作系统通常都是这样做的; Windows 对 32 位应用程序的支持尤其好,因为普通 Windows 系统上安装的大多数应用程序仍然是 32 位。
相反,情况并不成立,因为 x86-64 指令集(宽松地说)是 x86 架构的扩展,因此任何非 64 位 x86 处理器都不知道如何解释新的机器代码(即使它知道这一点,但它没有资源来运行它)。
至于编辑,您无法生成在任何地方本地运行的机器代码;在这种情况下,通常的解决方案是使用伪编译语言,该语言输出中间级机器代码,需要安装特定于体系结构的虚拟机才能运行(这里的经典示例是 Java 和 .NET)。如果您使用编译为“本机代码”的语言,则必须为每个目标平台生成可执行文件。
If you compile your code for i586 (actually what is commonly called x86) it should work fine on AMD64 (x86-64) processors, since x86-64 processors can execute "legacy" 32 bit code, as long as the OS supports this - and mainstream OSes usually do; Windows support for 32 bit applications in particular is really good, since most applications installed on the average Windows system are still 32 bit.
The contrary instead does not hold true, since the x86-64 instruction set is (loosely speaking) an expansion of the x86 architecture, so any non-64 bit x86 processor wouldn't know how to interpret the new machine code (and even if it knew it, it wouldn't have the resources to run it).
As for the edit, you can't generate machine code that runs natively everywhere; the usual solution in such cases is to use pseudo-compiled languages that output an intermediate-level machine code that needs an architecture-specific VM installed to be run (the classic example here is Java and .NET). If instead you use a language compiled to "native code", you have to generate an executable for each target platform.