Blocking and Non-blocking Assignments
continuous assignment
- each
assignstatement models a separate hardware gate, runs concurrently - multiple
assignstatements to the same variable will cause a conflict (multiple drivers)
| continuous_assignment.sv | |
|---|---|
fuctions
- used to encapsulate reusable combinational logic
| function_example.sv | |
|---|---|
blocking and non-blocking assignments
- blocking assignment (
=): statements execute sequentially, next statement waits for current to complete- order matters
- non-blocking assignment (
<=): statements execute concurrently, all right-hand sides are evaluated before any left-hand sides are updated- order does not matter
- DO NOT make assignments to the same variable in multiple non-blocking assignments within the same procedural block
what is the value of p and q after the rising edge of clk?
| example1.sv | |
|---|---|
answer: p = q = 5, or p = q = 8, depending on which always block executes first
| example2.sv | |
|---|---|
answer: p = q = 8
| example3.sv | |
|---|---|
answer: p = 8, q = 5
| example4.sv | |
|---|---|
answer: p = 10 or p = 11, depending on which non-blocking assignment is executed last. when synthesizing, the netlist may only keep one of the assignments, leading to unpredictable behavior.
| example5.sv | |
|---|---|
answer: p = q = 5, or p = q = 8, depending on which always block executes first
| example6.sv | |
|---|---|
what are the values of a, b, and c after the rising edge of clk?
answer: a = 5, b = 10, c = 0
a is scheduled to be updated to 5 at the end of the time step (non-blocking). b is assigned the old value of a (10) immediately (blocking). c is scheduled to be updated to the old value of b (which changed to be 10) at the end of the time step (non-blocking),