B4.2.2 Order Inside a Time Step

MediumImplement22 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
The lab's always blocks.
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);
CodeAnswer
1Yes
2No
CodeBranch
1The if branch
2The else branch
EntryYour decision
P_AFTERp after the first edge.
Q_AFTERq after the first edge.
DISPLAY_PWhat does the display at the first edge print for p?
ICARUS_ARecorded on Icarus 12 with line A written first: a after the first edge.
ICARUS_SWAP_ARecorded on Icarus 12 with line B written first: a after the first edge.
STANDARD_FIXESDoes the standard fix which of two always blocks runs first at one edge? Enter its code.
IN_ORDERDo the statements inside one begin-end block run in the order written? Enter its code.
FLAG_BRANCHflag is x. Which branch does if (flag) take? Enter its code.
COUNT_KNOWNAfter four edges with no reset, is count a known number? Enter its code.
P_LATERStarting 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

P AFTER

Input
p after the first edge.
Expected output
matches = 1

Nonblocking: p takes the old q.

Run samples executes all 3 public checks. Check all tests runs 14 checks on the server.

Icarus Verilog · server