Veriloglab
Veriloglab
Aim: To implement various logic gates using gate level, behavioural and data flow
modelling.
Theory:
NAND : This gate gives output low only if both the inputs are high otherwise gives
output high.
NOR : This gate gives output high if both the input are low and low otherwise.
XOR : This gate gives high input if both the input are different .
XNOR : This gate gives input high if both the input are same.
Code:
Gate level modelling:
module gates2(
input a,
input b,
output y1,
output y2,
output y3,
output y4
);
nand a2(y1,a,b);
nor a3(y2,a,b);
xor a4(y3,a,b);
xnor a5(y4,a,b);
endmodule
Behavioral modelling:
modulebehavioral_model(
inputa,b,
outputand_out,nor_out,nand_out,xor_out,xnor_out);
regand_out,nor_out,nand_out,xor_out,xnor_out;
always@(a or b)
begin
and_out=a&b;
nor_out=~(a|b);
nand_out=~(a&b);
xor_out=a^b;
xnor_out=~(a^b);
end
endmodule
moduledata_flow_model(
inputa,b,
outputand_out,nor_out,nand_out,xor_out,xnor_out);
assignand_out=a&b;
assignnor_out=~(a|b);
assignnand_out=~(a&b);
assignxor_out=a^b;
assignxnor_out=~(a^b);
endmodule
Test Bench:
module gates2_test;
// Inputs
reg a;
reg b;
// Outputs
wire y1;
wire y2;
wire y3;
wire y4;
gates2 uut (
.a(a),
.b(b),
.y1(y1),
.y2(y2),
.y3(y3),
.y4(y4)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
#100;
a = 1;
b = 0;
#100;
a = 0;
b = 1;
#100;
a = 1;
b = 1;
#100;
end
endmodule
RTL:
Waveforms:
Result: Various logic gates have been implemented using gate level ,behavioural and date
flow modeling