Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between using an initial block vs initializing a reg variable in systemverilog?

What is the difference between the following two examples with regards to simulation?

A)

reg a;
initial a = 1'b0;

and

B)

reg a = 1'b0;

Is it different for logic variables?

like image 797
supernun Avatar asked Dec 07 '22 21:12

supernun


2 Answers

The difference is initialization as part of a variable declarations execute before any process started by any initial or always constructs. If you wrote:

bit clk;
initial clk = 1;
always #5 clk++;
always @(posedge clk) ...;

There is a race condition as to whether the @(posedge clk) gets triggered at time 0 or time 10. However with:

bit clk = 1;
always #5 clk++;
always @(posedge clk) ...;

There is no race with the above. The first posedge will come at 10 time units.

like image 129
dave_59 Avatar answered Dec 29 '22 06:12

dave_59


The end result is the same, i.e., there won't be any difference from the end user perspective. The difference is that in the first case you are assigning the value during run time, and in the second case you are assigning the value during compile time.

like image 41
AndresM Avatar answered Dec 29 '22 05:12

AndresM