【问题标题】:Trying to build a PC (counter) for the nand2tetris , but I'm having some trouble with the logic尝试为 nand2tetris 构建 PC(计数器),但我在逻辑上遇到了一些问题
【发布时间】:2023-03-26 15:08:01
【问题描述】:

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

说明如下:

// 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]
 */

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

    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)

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

任何建议将不胜感激。

【问题讨论】:

    标签: hdl nand2tetris


    【解决方案1】:

    一些观察:

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

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

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

    祝你好运。你很亲密。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-24
      • 2013-09-02
      • 2021-11-12
      • 1970-01-01
      • 2016-09-22
      • 2016-01-13
      • 2021-05-26
      • 2021-12-16
      相关资源
      最近更新 更多