16 bit Not gate

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

16 bit Not gate

sarab
Hello guys,
i am trying to make 16 bit NOT gate...but i dont know how to define 16 bit buses.... i wrote this code below but it's not working...can you please give me the right code to implement it

// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not16.hdl

/**
 * 16-bit Not:
 * for i=0..15: out[i] = not in[i]
 */

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
    Nand(a[7]=in[7],b[7]=in[7],out[15]=out[15]);
}
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

cadet1620
Administrator
sarab wrote
Hello guys,
i am trying to make 16 bit NOT gate...but i dont know how to define 16 bit buses.... i wrote this code below but it's not working...can you please give me the right code to implement it

    Nand(a[7]=in[7],b[7]=in[7],out[15]=out[15]);
Think of a bus as a bundle of wires. The [] syntax selects one wire from a bus.

What you've done with this line of HDL is connect wire 7 from the in bus to the Nand's inputs and the Nand's output to wire 15 of the out bus.

You will need one line of HDL for each of the 16 wires.

Hint for building the Not16: use your Not chip.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

ybakos
In reply to this post by sarab
Sarab,
When working on the chips, I recommend making some quick drawings before you write any HDL code.

For Not16, you should realize that there is an input called a, which is a "16-bit bus," meaning that it is essentially 16 wires: a[0], a[1], ... a[15].

Here's a hint. To built Not16, you only need one kind of part... but you need 16 of them.

In the implementation you wrote above, you are trying to wire up a[7] to a Nand input's a[7], which does not exist. What inputs does Nand have? a and b.
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

ybakos
Looks like Mark is up earlier than me today.
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

sarab
In reply to this post by cadet1620
thanx for replying...
i tried this...but it's saying address out of range

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
    Not(in[0]=in[0],out[0]=out[0]);
    Not(in[1]=in[1],out[1]=out[1]);
    Not(in[2]=in[2],out[2]=out[2]);
    Not(in[3]=in[3],out[3]=out[3]);

    Not(in[4]=in[4],out[4]=out[4]);
    Not(in[5]=in[5],out[5]=out[5]);
    Not(in[6]=in[6],out[6]=out[6]);
    Not(in[7]=in[7],out[7]=out[7]);

    Not(in[8]=in[8],out[8]=out[8]);
    Not(in[9]=in[9],out[9]=out[9]);
    Not(in[10]=in[10],out[10]=out[10]);
    Not(in[11]=in[11],out[11]=out[11]);

    Not(in[12]=in[12],out[12]=out[12]);
    Not(in[13]=in[13],out[13]=out[13]);
    Not(in[14]=in[14],out[14]=out[14]);
    Not(in[15]=in[15],out[15]=out[15]);
}
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

sarab
In reply to this post by ybakos
thnx for replying....i tried the code below but its not working

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
    Not(in[0]=in[0],out[0]=out[0]);
    Not(in[1]=in[1],out[1]=out[1]);
    Not(in[2]=in[2],out[2]=out[2]);
    Not(in[3]=in[3],out[3]=out[3]);

    Not(in[4]=in[4],out[4]=out[4]);
    Not(in[5]=in[5],out[5]=out[5]);
    Not(in[6]=in[6],out[6]=out[6]);
    Not(in[7]=in[7],out[7]=out[7]);

    Not(in[8]=in[8],out[8]=out[8]);
    Not(in[9]=in[9],out[9]=out[9]);
    Not(in[10]=in[10],out[10]=out[10]);
    Not(in[11]=in[11],out[11]=out[11]);

    Not(in[12]=in[12],out[12]=out[12]);
    Not(in[13]=in[13],out[13]=out[13]);
    Not(in[14]=in[14],out[14]=out[14]);
    Not(in[15]=in[15],out[15]=out[15]);
}
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

cadet1620
Administrator
This post was updated on .
In reply to this post by sarab
Another useful resource is this list of Chip Interfaces.

All Not chips must follow the pattern "Not(in=___, out=___);"

In particular, since the Not is a single bit chip, its in and out can't have [].

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

sarab
then how to make a 16-bit bus using single Not gate :\
please help i'm stuck...
Actually i use xilinx....so i am confused
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

cadet1620
Administrator
What you'd like to write would be something like
for (i = 0; i < 16; i = i +1) begin
    Not(in=in[i], out=out[i]);        // out[i] = ~ in[i] 
end
but n2t HDL doesn't support for loops like VHDL so you need to explicitly write out each of the Nots.

(Copy-and-paste is your friend in most of the XXX16 chips 8-).

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

sarab
i wrote this but it's not working..plz help
CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
    Not(in[0]=in[0],out[0]=out[0]);
    Not(in[1]=in[1],out[1]=out[1]);
    Not(in[2]=in[2],out[2]=out[2]);
    Not(in[3]=in[3],out[3]=out[3]);

    Not(in[4]=in[4],out[4]=out[4]);
    Not(in[5]=in[5],out[5]=out[5]);
    Not(in[6]=in[6],out[6]=out[6]);
    Not(in[7]=in[7],out[7]=out[7]);

    Not(in[8]=in[8],out[8]=out[8]);
    Not(in[9]=in[9],out[9]=out[9]);
    Not(in[10]=in[10],out[10]=out[10]);
    Not(in[11]=in[11],out[11]=out[11]);

    Not(in[12]=in[12],out[12]=out[12]);
    Not(in[13]=in[13],out[13]=out[13]);
    Not(in[14]=in[14],out[14]=out[14]);
    Not(in[15]=in[15],out[15]=out[15]);
}
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

cadet1620
Administrator
sarab wrote
    Not(in[0]=in[0],out[0]=out[0]);
"in[0]=" and "out[0]=" are illegal because Not's in and out are single bit signals.
You need to have exactly "in=" and "out=" in all Not chips.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: 16 bit Not gate

sarab
Got it....thanx a lotttt