I was using ModelSim to do the simulation these days, and a problem came to me, that is:
And thers was a piece of verilog code like this:
if (cnt == `END_CNT)
...
reg [7:0] cnt;
always @(posedge clk)
if (en)
cnt <= cnt +1;
...
which means I define the reg right up to the assigning block, and I may use the variable before definition. It is my coding style and it works all right in Quartus.
But when I compiled the file in ModelSim, a "variables undefined " error would come, and I have to move the definition line above if
statement:
reg [7:0] cnt;
...
if (cnt == `END_CNT)
...
always @(posedge clk)
if (en)
cnt <= cnt +1;
...
I have a lot of code like this, and it bothers me so much. As a ModelSim beginner, I am wondering is there a compiler setting( I can not find any) to deal with my problem?