Implementing a 16 bit register in Nand2Tetris (HDL code)

Viewed 595

think I am most of the way there, and my hardware simulator accepts the chip, but when running the test script the comparison fails half way through, I'm guessing there is an issue with feeding the output of the DFF back into the Mux. Any advice would be much appreciated!

16-bit register: If load[t] == 1 then out[t+1] = in[t] else out does not change

CHIP Register {
IN in[16], load;
OUT out[16];

PARTS:
Mux (a=dffout, b=in[15], sel=load, out= dff);
DFF (in = dff, out = dffout, out = out[15]);
1 Answers

Without seeing the entire Register script and knowing more details about the error, it is impossible to determine where the error lies.

The snippet you have posted appears to implement a single bit of the register, so it appears that you are replicating this 16 times with individual Mux and DFF components. This is a bad practice because it makes it much easier to wire up things incorrect (you probably have a typo somewhere that is causing the error) and because it makes the code hard to read.

As with higher-level programming, the recommended practice is to write your code as concisely as possible and use existing hdl components whenever possible. At this point in the course, you should already have created a Bit() component; you will find it much easier to build your Register() out of them.

Related