AND GATE
//
testbench is here
module
test; reg
x,y; wire
z;
and_gate
test (.a(x), .b(y), .c(z)); //character after dot(.) is for signal initial
begin x=0;
y=0; #5
x=0; y=1; #5
x=1; y=0; #5
x=1; y=1; end initial
begin $monitor("a=%d
b=%d c=%d", x, y, z); $dumpfile("dump.vcd"); $dumpvars; #100
$finish; end endmodule |
//Design: And
Gate Level
module and_gate
(c, a, b); input a, b; output c; and (c, a, b); endmodule |
//Design: And
Data Flow
module and_gate
(c, a, b); input a, b; output c; assign c= a&b endmodule |
|
//Design: And
Behavioral or Algorithmic Level
module and_gate
(c, a, b); input a, b; output reg c; always @ (a or b)
begin if(a == 1 & b
== 1) begin c=1; end else c=0; end endmodule |