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?
When the execution flow comes to the "@(posedge clk) begin-end statement", the simulator wait for the triggering event(positive edge) on the clk. Until the triggering even happen, it blocks the following code and when it triggers, the execution flow goes to the next statement.
When you say $rose(a), it gives 1 or 0. Moreover $rose is set to one if the least significant bit of a changes from any value(0,x,z) to 1 else it is set to 0. 2) @posedge is an event.It is checked instantly.It does not return any value. You mean to say @(posedge) right?
Sure. The statement @(posedge clk); used in line says to stop the execution of the current code until the clock goes from low to high, after the previous statements were executed. In a simulator, or c program, it is posible to do this; you would suspend the process that is implementing that always block.
posedge means the transition from 0 to 1. negedge the oposit transition from 1 to 0. usualy a clock is used as posedge, so everytime your clock signals goes from 0 to 1. using posedge or negedge for the reset condition depends on the logic level you use or your design.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With