module counter
module counter
input mode,clk,reset;
output reg [7:0] count;
//internal wires
wire [7:0] count_mux_out, rst_mux_out;
//combinational logic
assign count_mux_out = mode ? count + 1'b1: count - 1'b1;
assign rst_mux_out = reset ? 8'b0 : count_mux_out;
//sequential logic
always @( posedge clk)
begin
count <= rst_mux_out;
end
endmodule
TEST BENCH
module counter_test();
// wire/reg declaration
reg clk, reset, mode;
wire [7:0] count;
// Module instantiation
counter dut_counter (.clk(clk), .mode(mode), .reset(reset), .count(count));
// Clock generation
always #5 clk=~clk;
// Driving inputs
initial
begin
clk=0;
reset=1; // active-high reset
#20; // waits 20ns
reset=0;
end
initial
begin
mode=1;
#180
mode=0;
#165
$finish;
end
end module