Re: pass through?

Posted by rekoil on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/pass-through-tp2549046p4026142.html

I did this a few times by using a "fake Mux". For example, to make x=y:

Mux(a=x, b=false, sel=false, out=y);

The main application for doing this, in my experience, is to have a second wire carry the same value as an existing wire. HOWEVER, I later learned that you don't ever need to do this - you can simply go back to the function that assigned the wire and add a second assignment to it, effectively teeing the output pin to multiple wires.

So, instead of:
Foo(in=in, out=x);
Mux(a=x, b=false, sel=false, out=y);

You can do:
Foo(in=in, out=x, out=y);

This works with bus subscripts as well - let's say I want to copy the LSB of a 16-bit bus to a different wire:
Foo16(in=in, out[0] = lsb, out=out);

It's never mentioned explicitly that "teed" output pins are legal in the HDL - I figured it out by accident - but after that realization, I was able to go back and reimplement every "fake Mux" I'd put in my code.