projects\01\Mux.hdl - Not always returns 1

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

projects\01\Mux.hdl - Not always returns 1

robotron
Hi,

I've written Not, And, Or, Xor. They've all passed the tests successfully. Some of them even use Not as a part, no problem there.

Now I've come to writing Mux and when I use Not it always returns 1 (regardless of the input). I've even tried using the built-in Not and it also return 1 all the time.
I have a feeling that something is wrong with my Mux file, but I just can't pinpoint it.

This is the Mux implementation:

// 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/Mux.hdl

/**
 * Multiplexor:
 * out = a if sel == 0
 *       b otherwise
 */

CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
                Not(in=sel, out=not1out);
                And(a=a, b=not1out, out=and1out);
                And(a=sel, b=b, out=and2out);
                Or(a=and1out, b=and2out, out=or1out);
}
Reply | Threaded
Open this post in threaded view
|

Re: projects\01\Mux.hdl - Not always returns 1

ybakos
You're close. Here's a question: what is wired to the Mux's out?

Reply | Threaded
Open this post in threaded view
|

Re: projects\01\Mux.hdl - Not always returns 1

robotron
You nailed it :) Should've mapped it to chip's OUT.

Thanks!