Along With The Test Bench:-I) All Basic Gates Ii) Half Adder, Full Adder, Half Subtractor, Full Subtractor (Using Structural Modelling Style)
Along With The Test Bench:-I) All Basic Gates Ii) Half Adder, Full Adder, Half Subtractor, Full Subtractor (Using Structural Modelling Style)
OUTPUT :
2. OR Gate
VERILOG CODE :
module or_gate(a,b,c);
input a,b;
output c;
assign c= a|b;
endmodule
TESTBENCH :
module or_tb;
reg a;
reg b;
wire c;
19EC037 EC382
3.NOT Gate
VERILOG CODE :
module not_gate(a,y);
input a;
output y;
assign y = ~a;
endmodule
TESTBENCH :
module not_gate_tb;
reg a;
wire y;
OUTPUT :
4.NOR Gate
VERILOG CODE :
module nor_gate(a,b,c);
input a,b;
output c;
assign c = ~(a | b);
endmodule
TESTBENCH :
module nor_tb;
reg a;
reg b;
wire c;
initial begin
a= 0; b = 0;
#100 a= 0; b=1;
#100 a=1;b=0;
#100 a=1; b=1;
end
initial begin
$monitor( " %t | a= %d; b= %d; | c = %d;" , $time, a,b,c);
$dumpfile ( "dumpnor.vcd");
$dumpvars();
end
endmodule
OUTPUT :
19EC037 EC382
5. XOR Gate
VERILOG CODE :
module xor_gate(a,b,c );
input a, b;
output c;
assign c = a^b;
endmodule
TESTBENCH :
module gate();
reg a,b;
wire y;
exor_gate uut (.a(a),.b(b),.y(y));
initial begin
#10 a=0;b=0;
#10 a=0;b=1;
#10 a=1;b=0;
#10 a=1;b=1;
end
endmodule
OUTPUT :
19EC037 EC382
6. XNOR Gate
VERILOG CODE :
module xnor_gate(a,b,y);
input a,b;
output y;
xnor X1(y,a,b);
endmodule
TESTBENCH :
module gate();
reg a,b;
wire y;
xnor_gate uut (.a(a),.b(b),.y(y));
initial begin
#10 a=0;b=0;
#10 a=0;b=1;
#10 a=1;b=0;
#10 a=1;b=1;
end
endmodule
OUTPUT :
19EC037 EC382
ii) HALF-ADDER
VERILOG CODE :
module half_adder(a,b,s,c);
input a,b;
output s,c;
xor X1(s,a,b);
and A1(c,a,b);
endmodule
TESTBENCH :
module testbench();
reg a,b;
wire s,c;
initial begin
#10 a=0;b=0;
19EC037 EC382
#10 a=0;b=1;
#10 a=1;b=0;
#10 a=1;b=1;
end
endmodule
OUTPUT :
HALF-SUBSTRACTOR
VERILOG CODE :
module half_sub(a,b,D,B);
input a,b;
output D,B;
wire x;
xor x1(D,a,b);
not N1(x,a);
and A1(B,x,b);
endmodule
19EC037 EC382
TESTBENCH :
module half_tb;
reg a;
reg b;
// Outputs
wire D;
wire B;
half_sub uut (
.a(a),
.b(b),
.D(D),
.B(B)
);
initial begin
// Initialize Inputs
#10 a = 0;b = 0;
#10 a = 0;b = 1;
#10 a = 1;b = 0;
#10 a = 1;b = 1;
end
endmodule
19EC037 EC382
OUTPUT :