Using sub-bus of internal bus

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using sub-bus of internal bus

Stephen Davies
(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!
Reply | Threaded
Open this post in threaded view
|

Re: Using sub-bus of internal bus

cadet1620
Administrator
Stephen Davies wrote
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);
}
In this case, do the sub-busing when you create x:

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

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

But I think you're implying that you want to use the full width output of the Not4 for something else, as in:

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

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

Notice that multiple wires are connected to Not4's 'out'.


--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Using sub-bus of internal bus

Stephen Davies
Perfect, thanks so much!