开发者

AMD64 run on i586 or vice-versa?

开发者 https://www.devze.com 2023-02-21 02:41 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消