Verilog code for OR gate with testbench






//assume a and b are inputs and y is output
module orgate (a, b, y);
input a, b;
output y;

assign y = a & b;

endmodule
 

TestBench 

module orgate_tb;
 wire t_y;
 reg t_a, t_b;
 orgate my_gate( .a(t_a), .b(t_b), .y(t_y) );
 initial begin     
$monitor(t_a, t_b, t_y); 
t_a = 1'b0; 
t_b = 1'b0;  
#5 
t_a = 1'b0; 
t_b = 1'b1; 
#5  
t_a = 1'b1; 
t_b = 1'b0; #5 
t_a = 1'b1; 
t_b = 1'b1;
end
endmodule

 



Comments

  1. Replies
    1. #5 means 5 seconds . the value of the variable a/(b) keeps switching between hign and low after every 5 seconds. hope u got it now.

      Delete

Post a Comment

Ad

Popular posts from this blog

VHDL Code for AND gate With Test Bench

VHDL code for Half adder with Test Bench

VHDL code for Full Adder With Test bench