CPU.hdl - 需要解释才能理解代码

时间:2015-05-29 10:43:23

标签: hdl

我有这个CPU.hdl代码。

CHIP CPU {

IN  inM[16],         // M value input  (M = contents of RAM[A])
    instruction[16], // Instruction for execution
    reset;           // Signals whether to re-start the current
                     // program (reset=1) or continue executing
                     // the current program (reset=0).

OUT outM[16],        // M value output
    writeM,          // Write into M? 
    addressM[15],    // Address in data memory (of M)
    pc[15];          // address of next instruction

PARTS:
Not(in=instruction[15], out=isAcmd);
Not(in=isAcmd, out=isCcmd);

// Create the ALU chip.
// First input to ALU is always D; 2nd is A or M based on inst[12]
Mux16(a=outA, b=inM, out=outAM, sel=instruction[12]);
ALU(x=outD, y=outAM, zx=instruction[11], nx=instruction[10], zy=instruction[9], ny=instruction[8], f=instruction[7], no=instruction[6], out=outM, out=outALU, out=inD, zr=zr, ng=ng);
//also need logic as to whether to write to M ... it's part of the instruction
And(a=isCcmd, b=instruction[3], out=writeM);
 .
 .
 .
}

我想了解CPU.hdl。我不理解PARTS之后的2行。他们做了什么?

2 个答案:

答案 0 :(得分:0)

PARTS实例化CPU内部的新组件。

例如。有一个NOT组件,名为in的端口连接到信号instruction[15]

答案 1 :(得分:0)

从书中可以看出:

  

为了弄清楚这个16位字是什么意思,如果可以打破   进入字段“i xx a cccccc ddd jjj”。 i位编码   指令类型,A指令为0,a为1   C-指令。

有问题的两条线是将指令[15]分成2个引脚。也许用DMux分割它们可能对你更有意义:

DMux(in=true, sel=instruction[15], a=aInstruction, b=cInstruction);

为两种方式绘制真值表,它应该对你有意义。