How can I expand a one-bit signal to multi bits?

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

How can I expand a one-bit signal to multi bits?

woodylcy
When I design ALU, for example there is a  one-bit input: ZX

I want to use these logic to implement the :setting zero function:
And16(a=x, b=zx, out=out1);
Xor16(a=x, b=out1, out=outzx);

   I firstly think it will work,because:  if zx=1, out1=x,   Xor(x,x)=0, if zx=0, out1=0, Xor(x,0)=x;
but the simulator says : zx is one-bit. I want to expand it to 16bits.

At last , I changed to use Mux16 to implement this.  

   further, I wonder  how to implement the "if ..  else.." in HDL ,except use Mux16.

 thanks a lot!!                 I am green.
Reply | Threaded
Open this post in threaded view
|

Re: How can I expand a one-bit signal to multi bits?

cadet1620
Administrator
Your And/Xor will work; it can be though of as "invert all 1s in x if zx is true".

Conceptually cleaner would be to do
    Not16(in=zx, out=zxNot);
    And16(a=x, b=zxNot, out=outzx);

except, as you found, the signal widths don't match. Using Mux16s is the way to go. They are indeed the "if/else" in the hardware world.

You can use a Mux16 to widen a signal it you really need to:
    Mux16(sel=signal, a=false, b=true, out=signal16);

--Mark