Predict what a simulator may print at one clock edge. Compare blocking and nonblocking writes, the order of two always blocks, and unknown values.
Hardware context: Registers updated by always blocks at one clock edge, a register with no reset and a flag nobody set. Explaining an x in a waveform.
The lab of the lesson swaps a = 1 and b = 2 with blocking writes in two always blocks. It swaps p = 1 and q = 2 with nonblocking ones. count has no reset, and flag is never set. Recorded values come from the site's Icarus 12.
This worksheet uses named constants. The first three entries show how to record your decisions.
Replace each unresolved value of 255 with your result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
always @(posedge clk) a = b; // line A
always @(posedge clk) b = a; // line B
always @(posedge clk) p <= q;
always @(posedge clk) q <= p;
always @(posedge clk) $display("at the edge: p=%0d", p);
| Code | Answer |
|---|---|
| 1 | Yes |
| 2 | No |
| Code | Branch |
|---|---|
| 1 | The if branch |
| 2 | The else branch |
| Entry | Your decision |
|---|---|
| P_AFTER | p after the first edge. |
| Q_AFTER | q after the first edge. |
| DISPLAY_P | What does the display at the first edge print for p? |
| ICARUS_A | Recorded on Icarus 12 with line A written first: a after the first edge. |
| ICARUS_SWAP_A | Recorded on Icarus 12 with line B written first: a after the first edge. |
| STANDARD_FIXES | Does the standard fix which of two always blocks runs first at one edge? Enter its code. |
| IN_ORDER | Do the statements inside one begin-end block run in the order written? Enter its code. |
| FLAG_BRANCH | flag is x. Which branch does if (flag) take? Enter its code. |
| COUNT_KNOWN | After four edges with no reset, is count a known number? Enter its code. |
| P_LATER | Starting from p = 1 and q = 2, the nonblocking pair swaps at every edge. What is p after EDGES edges? |
Examples
Example 1
P AFTER- Input
p after the first edge.
- Output
matches = 1
Nonblocking: p takes the old q.
Example 2
Q AFTER- Input
q after the first edge.
- Output
matches = 1
q takes the old p.
Example 3
DISPLAY P- Input
What does the display at the first edge print for p?
- Output
matches = 1
It runs before the nonblocking update lands, so it sees the old value.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For P_LATER, enter a constant expression using EDGES. Only this entry changes with the parameter. The supported integer range is 1 through 40, inclusive.
Hints
Hint 1
Every process reads first; the updates land together.
Hint 2
The value changes at once; the order of the blocks decides the result.
Hint 3
x stays x through arithmetic, and an if treats it as false.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
14 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path