2015-05-29 84 views
-3

我有這個CPU.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。我不明白部件後的兩條線。他們完成了什麼?

+0

這是哪一種語言?它不是VHDL或Verilog,這是兩種常用的HDL。 – Philippe

+0

@Philippe,這是nand2tetris的hdl。我在學校學習的語言。 – theOtherOne

回答

0

PARTS實例化CPU內部的新組件。

例如。有一個NOT成分,其中名爲in端口連接到信號instruction[15]

+0

我很抱歉,我沒有得到。你在說什麼? – theOtherOne

+1

加油。在來這裏之前,請閱讀您的教科書以提出這樣的基本問題。 – Philippe

0

從書:

爲了弄清楚這16位字的意思是,如果能夠打破 成字段「i xx a cccccc ddd jjj」。 i位編碼的指令類型爲 指令類型,對於A指令爲0,對於 C指令爲1。

這兩條線正在將指令[15]分成2個引腳。也許用DMUX分裂他們可能會更有意義給你:

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

畫出真值表兩種方式,它應該是有意義的你。