memoryramcpu-registershdlnand2tetris

Sub bus of an internal node may not be used. Nand2tetris hdl error while making the RAM8 chip in project3


I used 16 DMux8Way chips to take the 16 bit input and put in a temporary variable according to the address. The naming convention used to assign the temporary variable is (p, q, r, s, t, u, v, w, x, y, z).

Then to store those temporary variables I connected them with the input line of a Register chip (which takes 16 bit input).

Then, to output the desired Register state I simply used a Mux8Way16 chip.

But when I loaded the file in the Hardware simulator it gave me an error stating that,

p[0] sub bus of an internal node may not be used error

I don't understand I think I used all the pins properly but still getting the error and my code is not being loaded in the Hardware simulator software.

Here's my entire hdl code: Please help.

// 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/3/a/RAM8.hdl
/**
 * Memory of eight 16-bit registers.
 * If address is asserted, the value of the register selected by
 * address is set to in; Otherwise, the value does not change.
 * The value of the selected register is emitted by out.
 */
CHIP RAM8 {
    IN in[16], load, address[3];
    OUT out[16];

    PARTS:
    
    // Bit-wise storing the input number in a temporary 16 bit variable
    DMux8Way(in=in[0], sel=address, a=p[0], b=q[0], c=r[0], d=s[0], e=t[0], f=u[0], g=v[0], h=w[0]);
    DMux8Way(in=in[1], sel=address, a=p[1], b=q[1], c=r[1], d=s[1], e=t[1], f=u[1], g=v[1], h=w[1]);
    DMux8Way(in=in[2], sel=address, a=p[2], b=q[2], c=r[2], d=s[2], e=t[2], f=u[2], g=v[2], h=w[2]);
    DMux8Way(in=in[3], sel=address, a=p[3], b=q[3], c=r[3], d=s[3], e=t[3], f=u[3], g=v[3], h=w[3]);
    DMux8Way(in=in[4], sel=address, a=p[4], b=q[4], c=r[4], d=s[4], e=t[4], f=u[4], g=v[4], h=w[4]);
    DMux8Way(in=in[5], sel=address, a=p[5], b=q[5], c=r[5], d=s[5], e=t[5], f=u[5], g=v[5], h=w[5]);
    DMux8Way(in=in[6], sel=address, a=p[6], b=q[6], c=r[6], d=s[6], e=t[6], f=u[6], g=v[6], h=w[6]);
    DMux8Way(in=in[7], sel=address, a=p[7], b=q[7], c=r[7], d=s[7], e=t[7], f=u[7], g=v[7], h=w[7]);
    DMux8Way(in=in[8], sel=address, a=p[8], b=q[8], c=r[8], d=s[8], e=t[8], f=u[8], g=v[8], h=w[8]);
    DMux8Way(in=in[9], sel=address, a=p[9], b=q[9], c=r[9], d=s[9], e=t[9], f=u[9], g=v[9], h=w[9]);
    DMux8Way(in=in[10], sel=address, a=p[10], b=q[10], c=r[10], d=s[10], e=t[10], f=u[10], g=v[10], h=w[10]);
    DMux8Way(in=in[11], sel=address, a=p[11], b=q[11], c=r[11], d=s[11], e=t[11], f=u[11], g=v[11], h=w[11]);
    DMux8Way(in=in[12], sel=address, a=p[12], b=q[12], c=r[12], d=s[12], e=t[12], f=u[12], g=v[12], h=w[12]);
    DMux8Way(in=in[13], sel=address, a=p[13], b=q[13], c=r[13], d=s[13], e=t[13], f=u[13], g=v[13], h=w[13]);
    DMux8Way(in=in[14], sel=address, a=p[14], b=q[14], c=r[14], d=s[14], e=t[14], f=u[14], g=v[14], h=w[14]);
    DMux8Way(in=in[15], sel=address, a=p[15], b=q[15], c=r[15], d=s[15], e=t[15], f=u[15], g=v[15], h=w[15]);

    // Storing that temporary 16 bit variable into a register
    Register(in[0..15]=p, load=load, out=pout);
    Register(in[0..15]=q, load=load, out=qout);
    Register(in[0..15]=r, load=load, out=rout);
    Register(in[0..15]=s, load=load, out=sout);
    Register(in[0..15]=t, load=load, out=tout);
    Register(in[0..15]=u, load=load, out=uout);
    Register(in[0..15]=v, load=load, out=vout);
    Register(in[0..15]=w, load=load, out=wout);

    // Outputting the state of the register according to address.
    Mux8Way16(a=pout, b=qout, c=rout, d=sout, e=tout, f=uout, g=vout, h=wout, sel=address, out=out);
    
}

I tried to use

Register(in[0..15]=p, load=load, out=pout);
Register(in=p[0..15], load=load, out=pout);

Didn't work.

I also tried

Register(in[0..15]=p[0..15], load=load, out=pout);

didn't work either. And also

Register(in=p, load=load, out=pout);

Also did,'t work. Please help I don't know which pin is not being used. Note: All of these attempts resulted the same error.


Solution

  • Something to consider:

    In NAND2Tetris, everything happens at once during an update step in parallel. So there is no point in thinking about temporary variables to "hold" something. If you think you need to do that, you're making a conceptual error.

    I would suggest you review the description of the Register chip and in particular ask yourself "what happens to the data on the in pins when that register's load pin is 0"?

    On a more general note, I recommend re-reading Appendix 2 of the book, in particular A2.2 which goes into detail about how multi-bit buses are defined and used and A2.6 which has several examples near the end of the section which you will find to be applicable to your problem.