2

该项目旨在建立一个程序计数器。

说明如下:

// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/PC.hdl

/**
 * A 16-bit counter with load and reset control bits.
 * if      (reset[t] == 1) out[t+1] = 0
 * else if (load[t] == 1)  out[t+1] = in[t]
 * else if (inc[t] == 1)   out[t+1] = out[t] + 1  (integer addition)
 * else                    out[t+1] = out[t]
 */

我想出了所有的可能性如下 所有可能的输出 然后我开始:

    CHIP PC 
{
    IN in[16],load,inc,reset;
    OUT out[16];

    PARTS:
    // Put your code here:
    Register(in=in, load=true, out=thein);
    Register(in=in, load=false, out=theout);
    Inc16(in=theout, out=forinc);
    Register(in=forinc, load=true, out=theinc);
    Mux8Way16(a=theout, b=false, c=theinc, d=false, e=thein, f=false, g=thein, h=false, sel[2]=load, sel[1]=inc, sel[0]=reset, out=out);
}

我尝试了很多次,但是当时钟加载到时间 1+ 或类似的东西时都失败了。

由于这里定义的寄存器是 out(t+1) = out(t)

时间的输出是什么?+。我发现它真的很烦人。

任何建议将不胜感激。

4

1 回答 1

2

一些观察:

  1. 您将输出存储在寄存器中,这很好。但是,请注意,寄存器输出也是您的输入之一——它是 out[t]。

  2. 你不需要一个大的 Mux8Way16。有 4 种可能的不同输出,因此您可以在级联中使用多个 Mux16,或者(额外功劳)使用带有一些额外逻辑的单个 Mux4Way16 来计算两个选择位。

  3. 我通常发现最简单的做事方法是首先计算所有可能的输出(在本例中为 0、输入、寄存器 + 1 或寄存器),然后有逻辑来决定其中哪个实际得到输出。

祝你好运。你很亲密。

于 2021-07-14T09:05:31.867 回答