I created a simple Verilog module that displays random numbers. This module has a counter that counts up at every clock edge and at the press of a button, whatever the number is in the counter at that time is displayed. Here is my code:
module counter (input wire in, input wire clock, input wire reset, output reg [3:0] number)
reg [3:0] cur_state;
reg [3:0] next_state;
always @ (posedge clock) begin
if (reset) cur_state <= 4'b0;
else cur_state <= next_state;
end
// next state function
always @ (*) begin
next_state = cur_state + 4'b1;
end
// output
always @ (*) begin
if (in) number = cur_state;
end
number[3:0] is sent to a display module to display the corresponding number. (Inputs are debounced properly.)
Everything works fine on the FPGA, but the program notifies me that I've used a latch in output. Is there any way to prevent this and implement the same behavior using a flip-flop?
Thank you.


always @ (*) begin if (in) number = cur_state;what happens wheninis low? \$\endgroup\$