multi-bit internal signals

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

multi-bit internal signals

diffract|
Hello,
i'm trying to design a chip that gets a 16-bit number and outputs its negative (it's 2's complement)
the plan was to invert each one of the bits then add 1 to the result. when i tried to import the hdl file, HardwareSimulator said:

tempA[0]: sub bus of an internal node may not be used

here is the code i have:

CHIP negate {
        IN a[16];
        OUT out[16];
       
        PARTS:
        Not(in=a[0], out=tempA[0]);
        Not(in=a[1], out=tempA[1]);
        //until
        Not(in=a[15], out=tempA[15]);
       
        adder16bit(a=tempA, b="000000000000001", out=out);
}

1. how would i achieve such function? multi-bit internal nodes seem a bit too important to not support.
2. how do i assign a value to a multi-bit input? i did b="00000001" but it's invalid

thanks for looking
Reply | Threaded
Open this post in threaded view
|

Re: multi-bit internal signals

emekler0729
You should have already built the 16-bit Not gate which will simplify your code, instead of negating each sub bus individually you can negate the entire word. If you haven't built it, you can always use the built-in version. Also, check Apendix A.5.3 for some examples of the syntax for dealing with internal pins. You can't type in a specific 16-bit word for B's value (e.g. "0000000000000001"), but you can define each internal pin using the values "true" and "false".

Also, from the preview of the code you've posted, you will have syntax errors because you're using 1-bit Not gates with 1-bit outputs (tempA) but then when you are dealing with your Adder you're using the input "tempA" as a 16-bit input, if you keep your current format you will have to wire each tempA bit to each IN pin for the adder.

Hope this helps.
Reply | Threaded
Open this post in threaded view
|

Re: multi-bit internal signals

diffract|
ok, so i did it but i really hate how messy this looks.

CHIP negate {
        IN a[16];
        OUT out[16], overflow;
       
        PARTS:
        not16bit(in=a, out=tempA);
        setTo1(out=binaryOne);
        adder16bit(x=tempA, y=binaryOne, sum=out, overflow=overflow);
}

first off, i don't understand why i can use multi-bit internal signals as long as i don't subscript them explicitly; i hope this is a limitation that is planned to get fixed. i can use subscripts with internal bits in normal VHDL but not here.

and second, it seems i cannot connect a pin to high or low easily. By easily i mean using a statement like "binaryOne = false", or "set binaryOne false", i had to write a chip called setTo1 and use Not gates just so i can assign the binary values i wanted to the 16-bit input. this is very inefficient as i'm using a set of 16 Not gates unnecessarily just to assign a value.

CHIP setTo1 {
        OUT out[16];
       
        PARTS:
        Not(in=false, out=out[0]);
        Not(in=true, out=out[1]);
        Not(in=true, out=out[2]);
        //etc
}
Reply | Threaded
Open this post in threaded view
|

Re: multi-bit internal signals

cadet1620
Administrator
diffract| wrote
ok, so i did it but i really hate how messy this looks.

...

first off, i don't understand why i can use multi-bit internal signals as long as i don't subscript them explicitly; i hope this is a limitation that is planned to get fixed. i can use subscripts with internal bits in normal VHDL but not here.

and second, it seems i cannot connect a pin to high or low easily. By easily i mean using a statement like "binaryOne = false", or "set binaryOne false", i had to write a chip called setTo1 and use Not gates just so i can assign the binary values i wanted to the 16-bit input. this is very inefficient as i'm using a set of 16 Not gates unnecessarily just to assign a value.

The trick with internal buses is to create them the width that you need at the source. You can connect more than one wire to an output. For example, "Not16(..., out=out, out[0:7]=lowByteOut)" if you need both full width and half width outputs.

For constant inputs, true and false expand automatically to match the width of the input they are connected to. You can say, for instance, "in[0]=true, in[1..15]=false".

Using this technique you can write your Negate16 using just a Not16 and an Add16.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: multi-bit internal signals

keithnier

Thanks!
It really helps!!