这是我的代码:
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
Inc16(in = regout, out = incout);
Mux16(a = regout, b = incout, sel = inc, out = incdecision);
Mux16(a = incdecision, b = false, sel = reset, out = resetdecision);
Mux16(a = regout, b = resetdecision, sel = load, out = loaddecision);
Register(in = loaddecision, load = true, out = regout, out = out);
}
基本上,来自寄存器的值会递增,只有当inc为1(通过Mux检查)然后通过另一个可以重置它的Mux时接受,然后是另一个可以写或不写的Mux取决于负载的值。然后,无论出现什么值(无论是更改的值还是来自旧寄存器的值)都会被放入寄存器中。
我做错了什么?
答案 0 :(得分:2)
您似乎没有In
信号连接到任何东西。如果设置了load
信号,则需要使用适当的Mux16将In
值加载到寄存器中。
答案 1 :(得分:2)
更改resetdecision
和loaddecesion
的顺序。第一个具有更高的优先级。
Inc16(in=outpc, out=outincreased);
Mux16(a=outpc, b=outincreased, sel=inc, out=outinc);
Mux16(a=outinc, b=in, sel=load, out=outload);
Mux16(a=outload, b=false, sel=reset, out=outreset);
//And16(a=outLOAD, b[0..15]=reset, out=outreset);
Register(in=outreset, load=true, out=out, out=outpc);
答案 2 :(得分:0)
重载Mux16需要在加载Mux16之后发生。负载Mux16需要有" in"作为" b"销。
来自Nand2Tetris的工作代码:
Inc16(in = outandabout, out = incout);
Mux16( a = outandabout, b = incout, sel = inc, out = incinc);
Mux16( a = incinc, b = in, sel = load, out = loadout);
Mux16( a = loadout, b = false, sel = reset, out= outreset);
Register(in = outreset, load = true, out = out, out = outandabout);