Vlsi Lab
Vlsi Lab
Aim: To simulate and synthesize all the logic gates using Verilog HDL
module lab1(a,b,and_out,or_out,not_out,nand_out,xor_out,xnor_out,nor_out);
input a,b;
output and_out,or_out,not_out,nand_out,xor_out,xnor_out,nor_out;
assign and_out=a&b;
assign or_out=a|b;
assign not_out=~a;
assign nand_out=~(a&b);
assign xor_out=a^b;
assign xnor_out=~(a^b);
assign nor_out=~(a|b);
endmodule
module lab1_tb();
reg a,b;
wire and_out,or_out,not_out,nand_out,xor_out,xnor_out,nor_out;
lab1 uut(a,b,and_out,or_out,not_out,nand_out,xor_out,xnor_out,nor_out);
initial begin
a=0;b=0;#10;
a=0;b=1;#10;
a=1;b=0;#10;
a=1;b=1;#10;
#10 $finish;
end
endmodule
LAB - 2
module half1_tb();
reg a,b;
wire sum,carry;
half_add dut(.a(a) , .b(b) , .sum(sum) ,.carry(carry));
initial begin
a=0;b=0;
#10 a=0; b=1;
#10 a=1; b=0;
#10 a=1; b=1;
#10 $finish;
end
endmodule
(B)Design of a Full Adder Using Different Modeling Styles in Verilog and Simulation
input a,b,cin;
output sum,carry;
Endmodule
module lab2a_tb();
reg a, b, cin;
initial begin
#10 $finish;
end
Endmodule
(b) Dataflow Modeling:
input a,b,cin;
output sum,carry;
endmodule
© Behavioral Modeling:
input a,b,cin;
end
endmodule
© To design full adder using half adder and simulate the design
module full_adder1 (
input A, B, Cin,
);
half_adder ha1 (
.A(A),
.B(B),
.Sum(sum1),
.Carry(carry1)
);
half_adder ha2 (
.A(sum1),
.B(Cin),
.Sum(Sum),
.Carry(carry2)
);
endmodule
module half_adder (
input A, B,
output Sum, Carry
);
assign Sum = A ^ B;
endmodule
LAB - 3
TRUTH TABLE
module decoder_2_4c(
input A0,A1,E,
output D3,D2,D1,D0
);
endmodule
module decoder_2_4_tb;
reg E,A0,A1;
wire D3,D2,D1,D0;
decoder_2_4c dut(.E(E),.A0(A0),.A1(A1),.D0(D0),.D1(D1),.D2(D2),.D3(D3));
initial
begin
A0 = 1'bx; A1 =1'bx; E = 1'b0;
#10 $finish;
end
Endmodule
module decoder_2_to_4 (
);
Y0 = 1'b0;
Y1 = 1'b0;
Y2 = 1'b0;
Y3 = 1'b0;
if (EN) begin
default: begin
Y0 = 1'b0;
Y1 = 1'b0;
Y2 = 1'b0;
Y3 = 1'b0;
end
endcase
end
end
endmodule
Lab - 4
1. Design of 8x3 encoder and simulate the design.
module encoder(y0,y1,y2,y3,y4,y5,y6,y7,a,b,c);
input y0,y1,y2,y3,y4,y5,y6,y7;
output a,b,c;
assign a=y4|y5|y6|y7;
assign b=y2|y3|y6|y7;
assign c=y1|y3|y5|y7;
endmodule
module testbench();
reg y0,y1,y2,y3,y4,y5,y6,y7;
wire a,b,c;
encoder uut(y0,y1,y2,y3,y4,y5,y6,y7,a,b,c);
initial begin
end
endmodule
LAB - 5
1. Design of 2x1 & 4x1 multiplexer & Demultiplexer and simulate the design
module mux2_to_1(a,b,s,y );
input a,b,s;
output y;
assign y=s?a:b;
Endmodule
module mux2_to_1_tb();
reg a, b, s;
wire y;
initial begin
#10 $finish;
end
endmodule
module Mux4(A,B,C,D,S,Z);
input A,B,C,D;
input [0:1]S;
output reg Z;
always @(*) begin
case(S)
2'b00: Z = A;
2'b01: Z = B;
2'b10: Z = C;
2'b11: Z = D;
default: Z = 2'bxx;
endcase
end
endmodule
module Mux4_tb( );
reg A,B,C,D;
reg[0:1]S;
wire Z;
Mux4 uut(A,B,C,D,S,Z);
initial begin
end
endmodule
module demux2x1_dataflow (
input wire d,
output wire y1
);
endmodule
module tb_demux2x1_dataflow;
reg d;
reg sel;
demux2x1_dataflow uut (
.d(d),
.sel(sel),
.y0(y0),
.y1(y1)
);
initial begin
d = 1; sel = 0; #10;
d = 1; sel = 1; #10;
d = 0; sel = 0; #10;
d = 0; sel = 1; #10;
$finish;
end
endmodule
module demux4x1_dataflow (
input wire d, // Input data
);
endmodule
module tb_demux4x1_dataflow;
reg d;
demux4x1_dataflow uut (
.d(d),
.sel(sel),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3)
);
initial begin
$finish;
end
endmodule
LAB - 6
(a) To design and simulate Verilog coding for 8x1 multiplexer using 2x1
multiplexer
module mux2x1(a,b,s,y);
input a,b,s;
output y;
assign y=s?a:b;
endmodule
module mux8x1 (
);
endmodule
module tb_mux8x1;
wire y; // Output
mux8x1 uut (
.d(d),
.s(s),
.y(y)
);
initial begin
$finish;
end
endmodule
(b) To design and simulate Verilog coding for 8x1 multiplexer using case/ if else
statement (behavior level)
module lab6b(
output reg y
);
if (sel == 3'b000)
y = d[0];
y = d[1];
y = d[2];
y = d[3];
y = d[4];
y = d[5];
else if (sel == 3'b110)
y = d[6];
y = d[7];
else
y = 1'b0;
end
endmodule
module tb_mux8x1_if;
reg [7:0] d;
wire y;
lab6b uut (
.d(d),
.sel(sel),
.y(y)
);
initial begin
$finish;
end
endmodule
©To design and simulate Verilog coding for 8x1 Demultiplexer:using 2x1
Demultiplexer:
module demux2x1_dataflow (
input wire d,
output wire y1
);
endmodule
module demux8x1 (
output wire y7
);
demux2x1_dataflow demux0 (
.d(d),
.sel(sel[2]),
.y0(w0),
.y1(w1)
);
demux2x1_dataflow demux1 (
.d(w0),
.sel(sel[1]),
.y0(w2),
.y1(w3)
);
demux2x1_dataflow demux2 (
.d(w1),
.sel(sel[1]),
.y0(w4),
.y1(w5)
);
demux2x1_dataflow demux3 (
.d(w2),
.sel(sel[0]),
.y0(y0),
.y1(y1)
);
demux2x1_dataflow demux4 (
.d(w3),
.sel(sel[0]),
.y0(y2),
.y1(y3)
);
demux2x1_dataflow demux5 (
.d(w4),
.sel(sel[0]),
.y0(y4),
.y1(y5)
);
demux2x1_dataflow demux6 (
.d(w5),
.sel(sel[0]),
.y0(y6),
.y1(y7)
);
endmodule
module tb_demux8x1;
reg d;
demux8x1 uut (
.d(d),
.sel(sel),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3),
.y4(y4),
.y5(y5),
.y6(y6),
.y7(y7)
);
initial begin
$finish;
end
endmodule
(d) To design and simulate Verilog coding for 8x1 Demultiplexer using case/ if
else statement (behavior level)
module demux8x1_case (
input wire d,
output reg y7
);
y0 = 0;
y1 = 0;
y2 = 0;
y3 = 0;
y4 = 0;
y5 = 0;
y6 = 0;
y7 = 0;
case (sel)
3'b000: y0 = d;
3'b001: y1 = d;
3'b010: y2 = d;
3'b011: y3 = d;
3'b100: y4 = d;
3'b101: y5 = d;
3'b110: y6 = d;
3'b111: y7 = d;
default: ;
endcase
end
endmodule
module tb_demux8x1_case;
reg d;
demux8x1_case uut (
.d(d),
.sel(sel),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3),
.y4(y4),
.y5(y5),
.y6(y6),
.y7(y7)
);
initial begin
d = 1;
d = 0;
end
endmodule
LAB - 7
Design of 4 bit binary to gray converter & Gray to Binary Code Converter using Verilog
and simulate the design.
module binary_to_gray (
);
endmodule
module binary_to_gray_tb();
reg [3:0] binary;
binary_to_gray uut(.binary(binary),.gray(gray));
always
begin
$finish;
end
Endmodule
(B)Gray to Binary Code Converter
module gray_to1_binary (
);
endmodule
module gray_to_binary_tb1;
gray_to1_binary uut (
.gray(gray),
.binary(binary)
);
initial begin
$finish;
end
endmodule