Using sub-bus of internal bus

Posted by Stephen Davies on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Using-sub-bus-of-internal-bus-tp2548983.html

(There seems to be mention of this problem on other threads, but unfortunately there's a broken link and so I can't find the solution.)

This seems like it just plain ought to work:

CHIP Bus {
    IN a[4];
    OUT b;

    PARTS:
    Not4(in=a,out=x);
    Not(in=x[3],out=b);
}

where "Not4" is a simple 4-bit chip. However, there is an error on the last line, saying "sub bus of an internal node cannot be used."

Two questions:

1) Why is this? It sure seems like a normal, happy, healthy thing to do. If you can use a sub bus of an external pin, why not an internal pin?

2) Is there any way around this? In the above example, if I want to direct the MSB of the notted input to an output, is there any way to do it? I must admit I'm scratching my head to think of workarounds, and the only way I can think of is to back things all the way back to the external pin and duplicate the logic necessary:

CHIP Bus {
    IN a[4];
    OUT b;

    PARTS:
    Not4(in=a,out=x);
    Not(in=a[3],out=nota3);
    Not(in=nota3,out=b);
}

but this seems silly and is certainly not convenient or efficient in the general case.

Love your software, book, and educational paradigm, by the way!