Swap (cont’d)
always @(posedge CLK) begin A = B; end
always @(posedge CLK) begin B = A; end
always @(posedge CLK) begin A <= B; end
always @(posedge CLK) begin B <= A; end
The following code executes incorrectly
- One block executes first
- Loses previous value of variable
Non-blocking assignment fixes this
- Both blocks are scheduled by posedge CLK