/* String manipulator FSM that removes the second 1 from any * set of consecutive 1 inputs. */ module fsm (input logic clk, reset, in, output logic out); // present and next state enum logic [1:0] {S0, S1, S3} ps, ns; // next state logic always_comb case (ps) S0: if (in) ns = S1; else ns = S0; S1: if (in) ns = S3; else ns = S0; S3: if (in) ns = S3; else ns = S0; endcase // output logic assign out = in & (ps[1] | ~ps[0]); // sequential logic (DFFs) // synchronous reset always_ff @(posedge clk) if (reset) ps <= S0; // reset state else ps <= ns; endmodule // fsm