In order to construct the ALU, one needs (or at least that's how I did it), to AND (NOT(zx), x).
However x is a 16-bit bus, while zx is a one-bit signal.
I tried a lot of different ways to place [0..15] indexes, nothing worked.
Did I miss something, or was there absolutely no other way than creating a OneTo16 chip... or writing the indexes one by one in each and every such connection?
I chose the first solution which is incredibly ugly, being hacked with two nots, and the second solution would make someone mad after two chips. What did I miss?
Apart from this little quip, this is exactly like my Architecture 101 course,... except the final PC will work, rather than being simulated on paper, which makes it a LOT more exciting, great work!
Christer - why not take a more direct approach and not use your "dummy16"? You're merely abstracting/duplicating the work that needs to be done in Mux16. Think about And16. How did you build it? Mux16 is similar.
For your second question, if you need a pin that represents "off" use the keyword false.
FWIW you can make OneTo16 as
Mux16(sel=in, a=false, b=true, out=out)
Could you please explain to me why this works?
(In general I don't quite get how to use the true/false syntax. Or, for that matter, how to make buses interact with internal pins, since every time I try, I get error messages and just give up and find a clunky workaround.)
true and false can be used on the right side of any "=". This connects the pin, or all the pins if it is a bus, to one or zero.
SomePart(a=true, ... ); // Single-bit input 'a' set to 1
SomePart16(a=true, ...); // 16-bit input 'a' all bits set to 1
SomePart16(a[0..6]=false, a=true, a[8..15]=false, ...); // 16-bit input 'a' set to 128 decimal
Not16 (in=out, out=zr);
And (a=out, b=out, out=ng);
(While I'm at it, I'm getting an error message for the And gate, too: "Can't connect gate's output pin to part." Why is that?)
The error message would be clearer if it said "Can't connect chip's output pin to part." What it means is that pins named in the OUT line cannot be connected to inputs of parts used in the PARTS section.
Just like you can solder more than one wire to a physical pin, you can make more than one connection to a part's output pin: