Mux16

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

Mux16

Idrisadeniyi
Hello!

Please, I need a general idea on how I can implement mux16 and the rest of the multi 4way and 8way gates. Just a like a guide or an insight. every option I have tried for Mux16 has failed. The following is what I have done so far, but it resulted in comparison failure error message at line 4:

// 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/01/Mux16.hdl

/**
 * 16-bit multiplexor:
 * for i = 0..15 out[i] = a[i] if sel == 0
 *                        b[i] if sel == 1
 */

CHIP Mux16 {
    IN a[16], b[16], sel;
    OUT out[16];

    PARTS:
    // Put your code here:
        Not(in=sel, out=nots);
        Mux (a=a[0], b=b[0], sel=nots, out=out[0]);
        Mux (a=a[1], b=b[1], sel=nots, out=out[1]);
        Mux (a=a[2], b=b[2], sel=nots, out=out[2]);
        Mux (a=a[3], b=b[3], sel=nots, out=out[3]);
        Mux (a=a[4], b=b[4], sel=nots, out=out[4]);
        Mux (a=a[5], b=b[5], sel=nots, out=out[5]);
        Mux (a=a[6], b=b[6], sel=nots, out=out[6]);
        Mux (a=a[7], b=b[7], sel=nots, out=out[7]);
        Mux (a=a[8], b=b[8], sel=nots, out=out[8]);
        Mux (a=a[9], b=b[9], sel=nots, out=out[9]);
        Mux (a=a[10], b=b[10], sel=nots, out=out[10]);
        Mux (a=a[11], b=b[11], sel=nots, out=out[11]);
        Mux (a=a[12], b=b[12], sel=nots, out=out[12]);
        Mux (a=a[13], b=b[13], sel=nots, out=out[13]);
        Mux (a=a[14], b=b[14], sel=nots, out=out[14]);
        Mux (a=a[15], b=b[15], sel=nots, out=out[15]);
       
               
}



Reply | Threaded
Open this post in threaded view
|

Re: Mux16

WBahn
Administrator
So look at the compare file at line #4 (keep in mind that the column headers are line #1, so it's actually the third test you want) and look at your output. Do you see the problem?
Reply | Threaded
Open this post in threaded view
|

Re: Mux16

Idrisadeniyi
Yes. I could see it. But I expect it to give me the desired output. Could there be something wrong with my logic?
Reply | Threaded
Open this post in threaded view
|

Re: Mux16

WBahn
Administrator
Of course you expect it to give you the desired results.

They key is to look at the code that you wrote, not the code that you wanted to write.

Pick one of the bits that is wrong in your output and then walk through your design as you actually have it.

Which Mux processes that bit? What are the values of all of it's inputs?

What output value does it produce?

Does this agree with the .cmp file or the .out file?