指令代码

Instruction Code

我无法理解计算机是如何进行二进制运算的。

首先,存储单元中存储一条指令。

然后,CPU中的控制单元将这条指令存储在自己的指令寄存器(IR)中。

之后CU通过指令译码器(ID)对指令码中的操作码进行译码

假设操作码 = sum

如果是这样,我们需要两个操作数。有些书上说指令码的地址部分只有一个操作数的地址。

第二个操作数在哪里?

第二个操作数的地址在哪里?

大多数情况下,第二个操作数已经存储在 CPU、ALU(算术逻辑单元)的寄存器中。

指令序列可能如下所示:

lda 34        ' loads value from memory address 34 into ALU
add #20          ' adds value 20 to the value stored in ALU and stores the result in the ALU again
sda 78        ' stores the resulting value from the ALU in the memory at address 78

现代 CPU 有很多寄存器,因此现代 CPU 的指令序列可能如下所示:

load ax, 34        ' loads value from memory address 34 into AX
load bx, [si+2]       ' load the value from the address stored in register SI+2
add ax, bx            ' adds the value in register BX to the value in register AX and stores the result in AX
store di+5, ax        ' stores the value of register in memory at address stored in DI+5

希望这能帮您解决问题。