How to copy a bit value

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

How to copy a bit value

mslinklater
I'm stuck wondering what the simplest way to copy a bit value is. I want to copy the 15th bit of the output to an different bit. In real life I would just wire it on, but in the simulator that doesn't seem possible. My current thought is to use a Mux to select between false and true, but when I load the script the simulator throws an error:

Mux(a=false, b=true, sel=out[15], out=ng);

Fails with 'In HDL file..., Line xx, Can't connect gate's output pin to part'.

So two questions I suppose... why is the above Mux line failing ? And is this the best way to 'forward' a bus bit to an output bit ?

Thanks for an amazing course !
Reply | Threaded
Open this post in threaded view
|

Re: How to copy a bit value

cadet1620
Administrator
"sel=out[15]" is failing because "out" is a pin in the OUT declaration, which is not allowed to be used as an input, or it is an internal bus which is not allowed to be sub-bused.

Just like you can solder more than one wire to an output, HDL allows you to connect more than one wire/bus to an output. You can create multiple narrower sub-buses from an output just like additional single wire connections.

What you want to do is:
    SomePart(..., out=out, out[15]=something, out[__:__]=aBus, ...);
Reply | Threaded
Open this post in threaded view
|

Re: How to copy a bit value

mslinklater
Thank you, that makes sense. I now have a working ALU in 15 instructions... yay!