`timescale 1ns / 1ps module counter(CLK, IN, OUT); input CLK; input IN; output [1:0] OUT; reg [1:0] OUT = 0; always @(posedge CLK) begin OUT = IN ? OUT-1 : OUT+1; end endmodule