Is my Mux4Way16 codes right?

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

Is my Mux4Way16 codes right?

lonelyjohner
/**
 * 4-way 16-bit multiplexor.
 * out = a if sel==00
 *       b if sel==01
 *       c if sel==10
 *       d if sel==11
 */

CHIP Mux4Way16 {
    IN a[16], b[16], c[16], d[16], sel[2];
    OUT out[16];

    PARTS:
    // Put your code here:

    Mux16(a=a[0..15],b=b[0..15],sel=sel[0],out=out1[0..15]);
    Mux16(a=c[0..15],b=d[0..15],sel=sel[0],out=out2[0..15]);
    Mux16(a=out1[0..15],b=out2[0..15],sel=sel[1],out=out[0..15]);

}

when I tried to load my hdl file to the program, the feedback at the bottom indicated out1[0..15]: sub bus of an internal node may not be used. Does this mean that I should do the 16 ways separately instead of combining them as a bus?
Reply | Threaded
Open this post in threaded view
|

Re: Is my Mux4Way16 codes right?

cadet1620
Administrator
You don't need to say "a=a[0..15]". "a=a" means connecting all 16 bits. The error you are getting is because internal buses can only use [] notation when they are connected to inputs.  Just use "out=out1" to create an internal 16-bit bus named "out1".

--Mark