Lecture 2
Lecture 2
• These primitives are instantiated like modules except that they are
predefined in Verilog and do not need a module definition.
• These gates are instantiated to build logic circuits in Verilog
• There are two classes of basic gates:
• And/or gates
• Buf /note gates
And/Or Gate
• And / or gates have one scalar output and multiple scalar inputs.
• The first terminal in the list of gate terminals is an output and the
other terminals are inputs.
• The and/or gates available in Verilog are :
• Here the output terminal is denoted by out. Input terminals are
denoted by i1 and i2
• These gates are instantiated to build logic circuits in Verilog.
• Here the simple meaning of instantiation is invoking or calling.
1. and a1 (out,i1,i2);
2. nand na1 (out,i1,i2);
3. or or1 (out,i1,i2);
4. nor nor1 (out,i1,i2);
5. xor xor1 (out,i1,i2);
6. xnor xnor1 (out,i1,i2);
Buf/Not Gate
• Similarly Verilog also provides two basic buf/ not gate primitives.
• The symbol for these logic gates are shown below
Gate Instantiation of Buf/Not Gates
• // basic gate instantiations
• buf b1 (out,in);
• not n1 (out,in);
• //more than two outputs
• buf b1_2out (o1,o2,i);
• // gate instantiation without instance name
• not (o,i);
Example: X-Or Gate
• The output Y of X-or gate with A, B inputs is
Y=A’.B+ A.B’
• According to gate level modeling , it can be described using primitives
gate s as shown below
Gate Level Verilog Code
module xorgate(Y,A,B);
input A,B;
output Y;
wire A’,B’ ,C,D; // intermediate connection
not NOT1(A’,A);
not NOT2 (B’,B);
and AND1 (C,A’,B);
and AND2 (D,A,B’);
or OR (Y,C,D);
endmodule
Gate Level Design of Multiplexor
(MUX)
• Below diagram denotes a 2:1 MUX in terms of basic logic gates like
And, Or, Not etc.
• A & B are inputs and A1, B1 are intermediate inputs to or gate. Hence
they are declared as ‘wire’. The output is
Gate Level Design of Multiplexor
(MUX)
• The block diagram of 2:1 MUX is shown below.
Gate level Verilog code for 2:1 MUX
module mymux2_1(A,B,S,Y);
//Port declaration
output y;
input A,B,S;
//internal variable declarations
wire S1,A1,B1;
not n1 (S1,S);
and a1 (A1,A,S1);
and a2 (B1,B,S);
or o1(Y,A1,B1);
endmodule
Gate Level Half-Added
• A half adder adds two binary numbers and outputs as sum & carry as
shown below.
1. F=ΣA,B,C (0,2,6)=A’B’C’+A’BC’+ABC’
2. The corresponding logic diagram is as follows:
Code:
module System X (F, A,B,C);
output F;
input A,B,C;
wire An,Bn,Cn; // internal nets
wire mo,m2,m6;
not U0 (An,A); //Not’s
not U1 (Bn,B);
not U2 (Cn,C);
and U3(m0,An,Bn,Cn); //And’s
and U4(m2,An,B,Cn);
and U5(m6,A,B,Cn);
or U6 (F,m0,m2,m6); //Or
endmodule