NOT GATE
module not_gate(y, a);
output y;
input a;
assign y = ~a;
endmodule
module tb;
reg a;
wire y;
not_gate uut (y, a);
initial begin
a = 1'b0;
#100 a = 1'b1;
#100 a = 1'b0;
end
endmodule
OR GATE
module OR_Gate(Y, A, B);
output Y;
input A, B;
or (Y, A, B);
endmodule
module OR_GATE_TB;
reg a, b;
wire y;
OR_Gate m1 (y, a, b);
initial begin
a = 1'b0; b = 1'b0;
#100 a = 1'b0; b = 1'b1;
#100 a = 1'b1; b = 1'b0;
#100 a = 1'b1; b = 1'b1;
end
endmodule
NOT GATE
Module nand_gate(z, x, y);
output z;
input x, y;
wire w1;
and (w1, x, y);
not (z, w1);
endmodule
module nand_gate_tb;
wire z;
reg x, y;
nand_gate_data m2 (z, x, y);
initial begin
x = 1'b0; y = 1'b0;
#100 x = 1'b0; y = 1'b1;
#100 x= 1'b1; y = 1'b0;
#100 x = 1'b1; b = 1'b1;
end
endmodule
module nand_gate_data(z, x, y);
output z;
input x, y;
assign z = ~(x & y);
endmodule
module nand_gate_data_tb;
wire z;
reg x, y;
// Instantiate the NAND gate
nand_gate_data n1(z, x, y);
initial begin
// Test case 1
x = 1'b0; y = 1'b0;
#100;
// Test case 2
x = 1'b0; y = 1'b1;
#100;
// Test case 3
x = 1'b1; y = 1'b0;
#100;
// Test case 4
x = 1'b1; y = 1'b1;
#100;
end
endmodule
module nand_gate_beh(z, x, y);
output reg z;
input x, y;
always @ (x or y) begin
if (x == 1'b1 && y == 1'b1) begin
z = 1'b0;
end
else begin
z = 1'b1;
end
end
endmodule
`timescale 1ns/1ps
module tb_nand_gate_beh;
// Testbench signals
reg x, y;
wire z;
// Instantiate the NAND gate behavioral model
nand_gate_beh uut (
.z(z),
.x(x),
.y(y)
);
initial begin
$display("Time | x y | z");
$display("----------------");
// Test case 1
x = 1'b0; y = 1'b0; #10;
$display("%4t | %b %b | %b", $time, x, y, z);
// Test case 2
x = 1'b0; y = 1'b1; #10;
$display("%4t | %b %b | %b", $time, x, y, z);
// Test case 3
x = 1'b1; y = 1'b0; #10;
$display("%4t | %b %b | %b", $time, x, y, z);
// Test case 4
x = 1'b1; y = 1'b1; #10;
$display("%4t | %b %b | %b", $time, x, y, z);
$finish;
end
endmodule