Intel 和 AMD 处理器有相同的汇编程序吗?

发布于 2024-07-27 05:42:36 字数 265 浏览 9 评论 0原文

C语言被用来编写Unix以实现可移植性——使用不同编译器编译的同一个C语言程序会产生不同的机器指令。 为什么 Windows 操作系统能够在 IntelAMD 处理器?

The C language was used to write Unix to achieve portability—the same C language program compiled using different compilers produces different machine instructions. How come the Windows OS is able to run on both Intel and AMD processors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

鱼窥荷 2024-08-03 05:42:36

AMD 和 Intel 处理器 (*) 有大量共同指令,因此编译器或汇编器可以编写在两者上运行“相同”的二进制代码。

然而,不同的处理器系列,甚至来自一个制造商,都有自己的指令集,通常称为“扩展”或其他名称。 忽略x87协处理器,我第一次记得这是一个营销点是在一切突然都变了的时候“使用 MMX 技术”。 预期在任何处理器上运行的二进制代码要么需要避免扩展,要么在使用它们之前检测 CPU 类型。

Intel 的 Itanium 64 位架构与 AMD 的 x86-64 架构完全不同,因此有一段时间他们的 64 位产品不兼容(Itanium 与 x86 完全不同,而 x86-64 通过添加 64 位指令来扩展指令集)。 Intel 首先眨眼并采用了 x86-64,尽管仍然存在一些差异: AMD64 和 Intel 64 之间的差异

Windows 可能对几乎所有代码都使用通用的 x86 或 x86-64 指令集。 如果各种驱动程序和编解码器以多个版本提供,并且在询问 CPU 后选择正确的版本,我不会感到惊讶。

(*) 实际上,英特尔制造或已经制造了各种处理器,包括 ARM(英特尔的 ARM 处理器被称为 XScale ,但我认为他们已经卖掉了该业务)。 AMD 也生产其他处理器。 但我们知道您指的是哪些 Intel/AMD 处理器:-)

AMD and Intel processors(*) have a large set of instructions in common, so it is possible for a compiler or assembler to write binary code which runs "the same" on both.

However, different processor families even from one manufacturer have their own sets of instructions, usually referred to as "extensions" or whatever. Ignoring the x87 coprocessor, the first time I remember this being a marketing point was when everything suddenly went "with MMX technology". Binary code expected to run on any processor either needs to avoid extensions, or to detect the CPU type before using them.

Intel's Itanium 64-bit architecture was completely different from AMD's x86-64 architecture, so for a while their 64-bit offerings were non-compatible (and Itanium was nothing like x86, whereas x86-64 extended the instruction set by adding 64bit instructions). Intel blinked first and adopted x86-64, although there are still a few differences: Differences between AMD64 and Intel 64

Windows probably uses the common x86 or x86-64 instruction set for almost all code. I wouldn't be surprised if various drivers and codecs are shipped in multiple versions, and the correct one selected once the CPU has been interrogated.

(*) Actually, Intel makes or has made various kinds of processors, including ARM (Intel's ARM processors were called XScale, but I think they've sold that business). And AMD makes other processors too. But we know which Intel/AMD processors you mean :-)

要走就滚别墨迹 2024-08-03 05:42:36

AMD 与英特尔兼容。 否则,他们永远不可能在市场上站稳脚跟。

它们有效地克隆兼容。

AMD are Intel-compatible. Otherwise, they would never have gained a foothold in the marketplace.

They are effectively clone compatible.

笑红尘 2024-08-03 05:42:36

正如您所怀疑的,主流的 Intel 和 AMD 处理器具有相同的指令集。

Windows 不能在 ARMPowerPC 芯片,因为它在某种程度上依赖于底层指令集。

然而,大多数 Windows 是用 C++ 编写的(据我所知),它应该可以移植到其他体系结构。 Windows NT 甚至可以在 PowerPC 和其他体系结构上运行

As you suspect, the mainstream Intel and AMD processors have the same instruction set.

Windows does not run on ARM or PowerPC chips, for example, because it is somewhat dependent on the underlying instruction set.

However, most of Windows is written in C++ (as far as I know), which should be portable to other architectures. Windows NT even ran on PowerPC and other architectures.

以往的大感动 2024-08-03 05:42:36

Intel 的 80x86 CPU 和 AMD 的 80x86 “基本上是同一类”,但有些东西完全不同(例如虚拟机扩展 - SVM 与 VT-x),并且某些东西(扩展)可能受支持,也可能不受支持。 然而,同一制造商的不同 CPU 上的某些情况也有所不同(例如,有些 Intel 芯片支持 AVX2,有些则不支持)。

有多种方法可以处理差异:

  • 仅使用公共子集,以便相同的代码在所有 80x86 CPU 上运行(例如,将其视为 8086 芯片)。

  • 使用一系列 CPU 通用的功能子集,以便相同的代码可以在该范围内的所有 80x86 CPU 上运行。 这很常见(例如,“该软件需要支持 64 位扩展的 80x86 CPU(和操作系统)”)。

  • 使用安装时测试。 例如,可能有 4 个不同的软件副本(针对 4 个不同范围的 CPU 编译),安装程序将决定哪个副本对于要安装软件的计算机有意义。

  • 使用运行时测试。 例如,代码可以使用 CPUID 指令执行 if( AVX2_is_supported() ) { set_function_pointers_so_AVX2_is_used(); } else {set_function_pointers_so_AVX2_is_not_used(); }注意:某些编译器(Intel 的 ICC)可以自动生成执行运行时测试的代码。

这些并不是互斥的选项。 例如,安装程序可能决定安装 64 位版本(而不是 32 位版本),然后 64 位版本可能会在运行时检查支持哪些功能,并具有不同的代码来使用不同的功能。

另请注意,操作系统的不同部分可以单独处理。 例如,一个操作系统可以有 6 个不同的引导加载程序、4 个不同的“HAL”、4 个不同的内核和 3 个不同的“内核模块”来支持虚拟化; 其中一些东西可能会进行运行时测试,而另一些则可能不会。

Intel 和 AMD 处理器有相同的汇编程序吗?

几乎所有 80x86 的汇编器都支持几乎所有扩展(来自所有 CPU 制造商 - 例如 Intel、AMD、VIA、Cyrix、SiS...)。 一般来说; 由程序员(或编译器)来确保他们只使用他们知道存在的东西。 一些汇编器提供了一些功能来简化这一过程(例如 NASM 提供了一个 CPU ... 指令,以便程序员可以告诉汇编器在发现指定 CPU 不支持的指令时生成错误) 。

Intel's 80x86 CPUs and AMD's 80x86 are "mostly the same sort of", but some things are completely different (e.g. virtual machine extensions - SVM vs. VT-x) and some things (extensions) may or may not be supported. However, some things are different on different CPUs from the same manufacturer too (e.g. some Intel chips support AVX2 and some don't).

There are multiple ways to deal with the differences:

  • only use the common subset so the same code runs on all 80x86 CPUs (e.g. treat it like an 8086 chip).

  • use a subset of features that is common to a range of CPUs so the same code runs on all 80x86 CPUs in that range. This is very common (e.g. "this software requires an 80x86 CPU (and OS) that supports 64-bit extensions").

  • use install-time tests. For example, there might be 4 different copies of software (compiled for 4 different ranges of CPUs) where the installer decides which copy makes sense for the computer the software is being installed on.

  • use run-time tests. For example, code can use the CPUID instruction to do if( AVX2_is_supported() ) { set_function_pointers_so_AVX2_is_used(); } else {set_function_pointers_so_AVX2_is_not_used(); }. Note: Some compilers (Intel's ICC) can automatically generate code that does run-time tests.

These aren't mutually exclusive options. For example, the installer might decide to install a 64-bit version (and not a 32-bit version), and then the 64-bit version might check which features are supported at run-time and have different code to use different features.

Also note that different parts of an OS can be treated separately. For example, an OS could have 6 different boot loaders, 4 different "HALs", 4 different kernels, and 3 different "kernel modules" to support virtualisation; where some of these things might do run-time tests and some might not.

Do Intel and AMD processor have the same assembler?

Almost all assemblers for 80x86 support almost all extensions (from all CPU manufacturers - e.g. Intel, AMD, VIA, Cyrix, SiS, ...). In general; it's up to the programmer (or compiler) to make sure they only use things that they know exist. Some assemblers provide features to make this easier (e.g. NASM provides a CPU ... directive so that the programmer can tell the assembler to generate errors if it sees instructions that aren't supported on the specified CPU).

执笔绘流年 2024-08-03 05:42:36

AMD和Intel使用相同的指令集。

当您在 AMD 处理器或 Intel 处理器上安装 Windows 时,它不会在计算机上“编译”代码。

我记得大学期间很多人对这个问题感到困惑。 他们认为“设置”意味着它正在您的机器上编译代码。 事实并非如此。 大多数(如果不是全部)自由领域之外的 Windows 应用程序都是以二进制形式提供给您的。

至于可移植性,这不一定是100%正确的。 虽然 C 具有高度可移植性,但在许多情况下,为特定操作系统或系统编写代码将导致代码只能在该机器上编译/执行。 例如,某些 Unix 机器以不同的方式处理文件和目录,因此它可能不是 100% 可移植的。

AMD and Intel use the same instruction set.

When you install Windows on an AMD processor or an Intel processor, it doesn't "compile" code on the machine.

I remember many people being confused on this subject back during college. They believe that a "setup" means that it is compiling code on your machine. It isn't. Most, if not all, Windows applications outside of the free realms, are given to you as a binary.

As for portability, that isn't necessarily 100% true. While C is highly portable, in many cases writing for a specific OS or system will result in the code only being able to compile/executed on that box. For example, certain Unix machines handle files and directories differently, so it might not be 100% portable.

一个人练习一个人 2024-08-03 05:42:36

Intel 和 AMD 处理器有相同的汇编程序吗?
汇编器汇编一个在处理器上运行的程序,所以你的问题是有缺陷的。 处理器使用汇编器。

如果您的意思是 Intel 和 AMD 处理器可以运行相同的汇编程序吗? 那么答案是!!!

所有汇编程序都是从结构化文本文件汇编其他程序的程序。 Visual Basic 是汇编器的示例。

Do Intel and AMD processor have the same assembler?
An assembler assembles a program to be run on a processor, so your question is flawed. Processors do not use assemblers.

If you mean can Intel and AMD processor run the same assembler? Then the answer is yes!!!

All assemblers are programs that assemble other programs from structured text files. Visual Basic is an example of an assembler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文