nandgame--Level 5.2: CPU: Instruction decoder

第五章第二个任务:指令译码器。

指令是保存在存储器中,CPU运行时,先从存储器中取出指令,然后就需要对指令进行“译码”。就是翻译指令码,看它到底是要做什么操作和运算,译码后产生各种控制标志,作为控制器(Control Unit)的输入。

输入:一条指令

输出:各种标志和数据。

先看看任务描述:

nandgame--Level 5.2: CPU: Instruction decoder

nandgame--Level 5.2: CPU: Instruction decoder

 

任务说明:

这是一条16位的指令。

最高位(bit15)代表该指令是“数据”还是“运算”。0代表数据,1代表运算。

如果是数据指令,则将数据送到X寄存器。将A标志置1,其他标志置0.

如果是运算指令,则X寄存器为0。标志位:CI标志为1.其他标志位来自于指令的某个位。

 

分析:

1,最高位决定了A标志(暂不考虑bit5也会影响A标志)和CI标志。

CI=Bit15, A=(Bit15)非

nandgame--Level 5.2: CPU: Instruction decoder

2,当CI=0时为数据指令,X=I;当CI=1时为运算指令,X=0;

因此,可以由CI来选择X的输出。(D1接0)

nandgame--Level 5.2: CPU: Instruction decoder

3,标志位。

IT标志位:当CI为0时,IT=0;CI为1时,IT=Bit0

所以,IT=CI与(Bit0) = (Bit15) & (Bit0)

nandgame--Level 5.2: CPU: Instruction decoder

其他标志位类似。

A标志位特殊一点。当bit15=0表示数据指令时,A=1;当bit15=1表示运算指令时,A=Bit5。所以:A=(Bit15非)或(Bit15 与 Bit5)。

最终的结果有点乱:

nandgame--Level 5.2: CPU: Instruction decoder