Question

Is there any difference between

@(posedge Clk);
   a<= 1'b1;

and

@(posedge Clk)
   a<= 1'b1;

Note the semicolon after Clk. I came across similar lines of code when I was browsing through a testbench. I did some simple experiments and I could not find any differences during simulation. Will the sequence of execution for the code following these lines change in any way due to the presence/absence of the semicolon?

Was it helpful?

Solution

You're correct -there's no behavioural difference.

The semicolon version is: Wait. Do this. The non-semicolon version is: Wait then do this. You'll sometimes see this form used in one-liners:

@(posedge Clk) a<= 1'b1;

OTHER TIPS

The BNF syntax for any procedural statement is essentially

statement_item := 
        {procedural_timing_control} statement;

This means you can have 0 or more timing controls in front of any statement. In your example @(posedge Clk) is a timing control and a<= 1'b1; is the statement.

If your example were inside a fork/join, there would be a behavioral difference because the former is two statements; the later is one statement.

fork
  @(posedge Clk); a<=1'b1;
join

In this case, the 2 statements are started in parallel - a would not wait for the posedge to be assigned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top