cpu-architecture - 什么是机器指令?

标签 cpu-architecture instruction-set instructions microcoding

The user's program in main memory consists of machine instructions and data. In contrast, the control memory holds a fixed microprogram that cannot be altered by the occasional user. The microprogram consists of microinstructions that specify various internal control signals for execution of register microoperations. Each machine instruction initiates a series of micro instructions in control memory. These microsinstructions generates microoperations to fetch the instruction for main memory; to evaluate the effective address, to execute the operation specified by the instruction, and to return control the fetch phase in order to repeat the cycle for the next instruction

我在这里并不完全理解机器指令、微指令和微操作之间的区别。我当然明白,根据给定的段落,微指令是中级指令,但其他 2 条指令中哪一条更接近机器语言。 CLA、ADD、STA、BUN、BSA、AND等是机器指令还是微操作?

最佳答案

CPU 对外显示为能够执行机器指令 的设备。例如,

mov (%esi,%ebx,4), %edx

是一条机器指令,它将地址 ESI+4*EBX 处的 4 个字节的数据移动到寄存器 EDX 中。 机器指令是公开的 - 它们由 CPU 制造商在用户手册中发布。 gcc 等编译器将输出包含机器指令的文件,这些文件通常以 EXE/DLL 文件结尾。

如果你仔细看上面的指令,你会发现这是一个相当复杂的操作。它涉及一些算术(乘法和加法)来获取内存地址,然后将数据从该地址移动到寄存器中。从 CPU 的角度来看,使用已经存在的算术单元也是有意义的。因此,将此指令分解为微指令是很自然的。从本质上讲,mov指令是CPU内部实现的,是用微指令编写的微程序。然而,这是 CPU 的一个实现细节。 微指令是 CPU 内部的,除 CPU 制造商外,任何人都看不到它们。

微指令有几个好处:

  • 他们简化了内部 CPU 架构、设计和测试,从而降低了单位成本
  • 它们使创建丰富而强大的机器指令集变得容易(您只需要以不同的方式组合微指令)
  • 它们在不同的 CPU 上提供一致的机器语言(例如 Xeon 和 Pentium 都实现了基本的 x86_64 指令集,尽管它们在硬件上有很大不同)
  • 创建优化(即一个 CPU 上的相同指令可以由硬件实现,另一个可以在微指令中模拟)
  • 修复错误(例如,您可以在机器运行时修复 Spectre 漏洞,而无需购买新的 CPU 和打开服务器)

有关详细信息,请参阅 https://en.wikipedia.org/wiki/Micro-operation

关于cpu-architecture - 什么是机器指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65916789/

相关文章:

c++ - 有多少 "large"对象被带入缓存?

c - 包容还是排他? Intel Core IvyBridge 处理器中的 L1、L2 缓存

x86 - amd和intel程序员模型兼容性

c - 模拟 jg 指令(datalab 的 isGreater)

multithreading - 多核处理器的关键部分

c++ - 如何反汇编编译器生成的代码?

c++ - 用于检测 BMI2 指令集的编译器宏

assembly - CPU如何区分 'CALL rel16'(E8 cw)和 'CALL rel32'(E8 cd)?

assembly - 汇编程序错误。 : Bad instruction

C 代码循环性能 [续]