试图为 nand2tetris 构建一台 PC计数器,但我在逻辑上遇到了一些问题

问题描述

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

说明如下:

// 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,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)

time 的输出是多少?+。我觉得这很烦人。

任何建议将不胜感激。

解决方法

一些观察:

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

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

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

祝你好运。你们很亲近。