module TFF(input in, input reset, input clk, output reg out=0); reg last = 0; always @(posedge clk) begin if (reset) out = 0; else if (in && !last) out = ~out; last <= in; end endmodule