Realization of Logic Gates Using Gate - : Level Modeling
Realization of Logic Gates Using Gate - : Level Modeling
Output
and
or
~A
~b
nand
nor
xor
Xnor
input a,b,
output [7:0] y
);
and
A1 (y[0],a,b);
or
A2 (y[1],a,b);
not
A3 (y[2],a);
not
A4 (y[3],b);
nand A5 (y[4],a,b);
nor
xor
A6 (y[5],a,b);
A7 (y[6],a,b);
xnor A8 (y[7],a,b);
endmodule
7408N_VHDL
7404N_VHDL
7432N_VHDL
U6A
U3A
U2A
U9A
7404N_VHDL
a
b
a
b
y[0]=ab
AND Gate
y[1]=a+b
a
b
y[2]=a'
a
b
OR Gate
a
NOT Gate
b
y[3]=b'
NOT Gate
a
b
7400
y[4]=(ab)'
NAND Gate
y[5]=(a+b)'
NOR Gate
y[6]=ab'+a'b
XOR Gate
a
b
y[7]=ab+a'b'
XNOR Gate
74AC1
module ha_gate_primitive(
input a,b,
output sum,carry
);
xor
A1
and A2
endmodule
(sum,a,b);
(carry,a,b);
Input
Output
Sum
Carry
7408N_VHDL
U8A
74AC11002N_VHDL
U3A
a
b
Sum=ab'+a'b
Carry=ab
HALF ADDER
input a,b,cin,
output s,cout
Input
Output
c in
c out
);
wire
z1,z2,z3;
7408N_VHDL
U2A
7408N_VHDL
7486D_VHDL
U4A
U1A
U5A 7432N_VHDL U3A
7486N_VHDL
OR1
endmodule
(cout,z2,z3);
a
b
cin
z1
Sum
z2
Cout
z3
FULL ADDER
module mux2to1_gp(
Selict
line
Input
Output
W1
W0
input [1:0] w,
input s,
input f
);
7400N_VHDL
7432N_VHDL
U6A
U1A
U3A 7404N_VHDL
U2A
7400N_VHDL
wire
z1,z2,z3;
not A1 (z1,s);
and A2 (z2,w[0],z1);
w[0]
z2
and A3 (z3,w[1],s);
or
A4 (f,z2,z3);
endmodule
z1
w[1]
z3
2:1 MUX
Output
and
or
~A
~b
nand
nor
xor
Xnor
input a,b,
output [7:0] y
);
assign y[0]=a&b;
7408N_VHDL
7404N_VHDL
7432N_VHDL
U6A
U3A
U2A
U9A
7404N_VHDL
assign y[1]=a|b;
assign y[2]=~a;
assign y[3]=~b;
assign y[4]=~(a&b);
assign y[5]=~(a|b);
a
b
a
b
assign y[6]=a^b;
assign y[7]=a~^b;
endmodule
y[0]=ab
AND Gate
y[1]=a+b
a
b
y[2]=a'
a
b
OR Gate
a
NOT Gate
b
y[3]=b'
NOT Gate
a
b
7400
y[4]=(ab)'
NAND Gate
y[5]=(a+b)'
NOR Gate
y[6]=ab'+a'b
XOR Gate
a
b
y[7]=ab+a'b'
XNOR Gate
74AC1
input a,b,cin,
output s,cout
);
assign s = a ^ b ^ cin;
assign cout = (a & b) | (cin & (a ^ b ));
endmodule
Input
Output
c in
c out
U2A
7408N_VHDL
7486D_VHDL
U4A
U1A
U5A 7432N_VHDL U3A
7486N_VHDL
a
b
cin
z1
Sum
z2
Cout
z3
FULL ADDER
module binary_grey(
input [3:0] b,
output [3:0] g);
assign g[3] = b[3];
assign g[2] = b[3] ^ b[2];
assign g[1] = b[2] ^ b[1];
assign g[0] = b[1] ^ b[0];
Grey code
B
3
B
2
G0
74AC11002N_VHDL
U2A
74AC11002N_VHDL
U1A
74AC11002N_VHDL
U8A
endmodule
b[3]
b[2]
b[1]
b[0]
g[3]
g[2]
g[1]
g[0]
module mux2to1_conditional_operators(
Selict line
W
1
W0
output f
);
7400N_VHDL
7432N_VHDL
U6A
U1A
U3A 7404N_VHDL
U2A
7400N_VHDL
endmodule
w[0]
s
w[1]
2:1 MUX
Output
input s,w0,w1,
assign f = s? w1 : w0;
Input
module mux4to1_conditional_operator(
input [1:0] s,
input [3:0] w,
output f
);
assign f=s[1]?(s[0]? w[3] : w[2]):(s[0]?w[1]:w[0]);
endmodule
Input
Output
S
1
S0
W3
W2
W1
W0
U4A
7411D_VHDL
7404N_VHDL
7411D_VHDL
U7A
U8A
7432N_VHDL
U9A
U5A
7411D_VHDL
U10A
7411D_VHDL
input [3:0] w,
output f
);
7404N_VHDL
U11A
wire z1,z2,z3,z4,z5,z6;
not A1 (z1,s0);
not A2 (z2,s1);
and A3 (z3,w[0],z1,z2);
w[0]
s[0]
and A6 (z6,w[3],s1,s0);
or A7 (f,z3,z4,z5,z6);
endmodule
z1
w[1]
z4
f
w[2]
and A4 (z4,w[1],z2,s0);
and A5 (z5,w[2],s1,z1);
z3
s[1]
z2
z5
w[3]
z6
input a,b,cin,
output s,cout
);
ha_gate_primitive
HA1 (a,b,z2,z1);
ha_gate_primitive
HA2 (cin,z2,s,z3);
Output
c in
c out
or OR1 (cout,z1,z3);
7432N_VHDL
U5A
endmodule
module ha_gate_primitive(
input a,b,
output sum,carry
xor
A1
(sum,a,b);
and
A2
(carry,a,b);
cout
HA1
);
endmodule
z1
z2
z3
HA2
cin
FULL ADDER
W[0]
W[1]
W[2]
m[0]
16:1 MUX
4:1 MUX
W[3]
output f
);
wire [0:3]m;
mux4to1 MUX1 (s[3:2],w[0:3],m[0]);
W[4]
W[5]
W[6]
m[1]
4:1 MUX
W[7]
4:1 MUX
W[9]
W[10]
m[2]
4:1 MUX
W[11]
W[12]
W[13]
W[14]
m[3]
4:1 MUX
W[15]
module mux4to1(
input [1:0] s,
input [3:0] w,
output f
);
assign f= s[1]? (s[0]? w[3] : w[2]) : (s[0]? w[1] : w[0]);
endmodule
S[3] S[2]
S[1] S[0]
module pa(
input [3:0] fa,fb,
input fcin,
output [3:0] fsum,
output fcout
);
wire [3:1]ft;
fa FA1 (.a(fa[0]),.b(fb[0]),.cin(fcin),.s(fsum[0]),.cout(ft[1]));
fa FA2 (.a(fa[1]),.b(fb[1]),.cin(ft[1]),.s(fsum[1]),.cout(ft[2]));
fa FA3 (.a(fa[2]),.b(fb[2]),.cin(ft[2]),.s(fsum[2]),.cout(ft[3]));
fa FA4 (fa[3],fb[3],ft[3],fsum[3],fcout);
endmodule
module fa (
input a,b,cin,
output s,cout
);
assign s=a^b^cin;
assign cout=(a&b)|(b&cin)|(a&cin);
endmodule
FB[3] FA[3]
A
FA4
FB[2] FA[2]
Cout S
FA3
Cin
A
FA2
Cin
Cout S
FT[3]
FCout FSum[3]
FB[1] FA[1]
B
Cin
Cout S
FT[2]
FSum[2]
FB[0] FA[0]
FA1
Cin
FCin
Cout S
FT[1]
FSum[1]
FSum[0]
PARALLEL ADDER
input s0,s1,w,
output [3:0] y
);
wire z1,z2;
7410N_VHDL
U10A
7404N_VHD
U9A
7410N_VHDL
7410N_VHDL
U4A
U8A
7410N_VHDL
U11A
7404N_V
U7A
assign z1=~s1;
assign z2=~s0;
assign y[0]=w&z1&z2;
assign y[1]=w&z1&s0;
assign y[2]=w&s1&z2;
assign y[3]=w&s1&s0;
endmodule
s1
s0
y[0]
z1
y[1]
y[2]
z2
y[3]
1:4 DEMUX
module ha(
input a,b,
output sum,carry);
xor
A1
(sum,a,b);
and
A2
(carry,a,b);
endmodule
7408N_VHDL
U8A
74AC11002N_VHDL
U3A
Input
a
b
Sum=ab'+a'b
Carry=ab
HALF ADDER
Output
Sum
Carry
initial
begin
fa=0 ; fb=0 ; fcin=0;
#1 fa=4'b0101 ; fb=4'b1011 ; fcin=1;
FB[3] FA[3]
FB[2] FA[2]
FB[1] FA[1]
FB[0] FA[0]
FA4
FA3
Cin
Cout S
Cout S
FT[3]
FCout FSum[3]
FA2
Cin
Cin
Cout S
FT[2]
FSum[2]
FA1
Cin
Cout S
FT[1]
FSum[1]
PARALLEL ADDER
FSum[0]
FCin
module pa(
input [3:0] fa,fb,
input fcin,
output [3:0] fsum,
output fcout
);
wire [3:1]ft;
fa fulladder1 (.a(fa[0]),.b(fb[0]),.cin(fcin),.s(fsum[0]),.cout(ft[1]));
fa fulladder 2 (.a(fa[1]),.b(fb[1]),.cin(ft[1]),.s(fsum[1]),.cout(ft[2]));
fa fulladder 3 (.a(fa[2]),.b(fb[2]),.cin(ft[2]),.s(fsum[2]),.cout(ft[3]));
fa fulladder4 (fa[3],fb[3],ft[3],fsum[3],fcout);
endmodule
module fa (
input a,b,cin,
output s,cout
);
assign s=a^b^cin;
assign cout=(a&b)|(b&cin)|(a&cin);
endmodule
initial
Selict
lines
begin
s = 0 ; w = 0;
#1 s=2'b00 ; w=4'b0001;
#1 s=2'b00 ; w=4'b0000;
#1 s=2'b01 ; w=4'b0010;
Input
Output
S
1
S0
W3
W2
W1
W0
#1 s=2'b01 ; w=4'b0000;
#1 s=2'b10 ; w=4'b0100;
#1 s=2'b10 ; w=4'b0000;
#1 s=2'b11 ; w=4'b1000;
#1 s=2'b11 ; w=4'b0000;
#10 $stop;
end
endmodule
module mux4to1 (
input [1:0] s,
input [3:0] w,
output f
);
assign f= s[1]? (s[0]? w[3] : w[2]) : (s[0]? w[1] : w[0]);
endmodule
W[0]
module mux16to1_using_4to1(
input [3:0] s,
W[1]
W[2]
m[0]
16:1 MUX
4:1 MUX
W[3]
input [0:15] w,
output f);
wire [0:3]m;
mux4to1 MUX1 (s[3:2],w[0:3],m[0]);
W[4]
W[5]
W[6]
m[1]
4:1 MUX
W[7]
4:1 MUX
W[8]
W[9]
W[10]
m[2]
4:1 MUX
W[11]
endmodule
W[12]
W[13]
module mux4to1 (
W[14]
m[3]
4:1 MUX
W[15]
input [1:0] s,
input [3:0] w,
S[3] S[2]
output f);
assign f= s[1]? (s[0]? w[3] : w[2]) : (s[0]? w[1] : w[0]);
endmodule
S[1] S[0]
always@(w,en)
case({en,w})
3'b100:y=4'b1000;
3'b101:y=4'b0100;
3'b110:y=4'b0010;
3'b111:y=4'b0001;
default:y=4'b0000;
endcase
endmodule