Naveen Kumar
Naveen Kumar

Reputation: 33

Non blocking Statements execution in verilog

I am new to verilog, can anyone please explain me how does these statements execute.

always@(posedge clock) begin
A <= B ^ C;
D <= E & F;
G <= H | J;
K <= G ? ~&{A,D} : ^{A,D}
end

As far I can tell, the right side is first executed. Hence, the values for A, D, G, K are first calculated. While calculating value for K, depending on value of G the either first or second expression would execute. Can anyone please explain this operation. Please also tell how the last statement gets synthesized as this entire code is inside a always block and with positive edge clock. Thanks in advance.

Upvotes: 1

Views: 492

Answers (1)

sharvil111
sharvil111

Reputation: 4381

A nonblocking assignment evaluates the RHS expression at the beginning of a time step and schedules the LHS update to take place at the end of the time step.

In Verilog, there is a well defined event queue as shown below. For each and every timestamp, all the regions are evaluated. If there are any events to be executed in current timestamp, then they are triggered. Once all the events of current timestamp are triggered, then only simulation time moves forward.

Event regions

Here, the RHS of ALL the expressions are evaluated at the beginning of the timestamp of posedge of clock. Hence, the values of B^C, E&F,H|J,G ? ~&{A,D} : ^{A,D} are evaluated and stored internally in the simulator.

Thereafter, the LHS are updated as the simulation progresses to NBA region of the same timestamp.

The values of G,AandDare not updated in active region. Hence, while calculating the value ofK, the previous values ofG,AandDare taken in the Active region. Then, all the veriables;G,A,DandK` are updated simulatanously.

I have made an example code over EDAPlayground. The waveforms might be helpful.

As far as last statement is concerned, I guess it will create a flop with mux (with Select=G and Inputs as nand(A,D) , xor(A,D) ) as input.

Upvotes: 1

Related Questions