Skip to content
code0.HDL

33Verification

Return the current ticket

Problem

issueTicket is an ActionValue expression with two simultaneous obligations: return the ticket visible at entry to the action and schedule the following ticket for the next call. The register update is already correct, but the return expression predicts that update too early. The starter therefore prints 41 and 42 where the contract requires 40 and 41.

Repair only the editable function. Keep its ActionValue#(UInt#(8)) type, its actionvalue block, the single state advance, and the supplied mkTop.

Read and trace before editing

Start at issueTicket, not at the display rule. Mark the register read in the scheduled write, the value used by return, and the <- binding in issueTwo. Both expressions in the action observe the register's entry value; the <= write becomes visible only in the next state.

Trace the starter before Run:

  1. Entry state 40 schedules 41, while the current return expression computes the first visible ticket.
  2. The next firing enters with 41 and schedules 42.
  3. The issued register follows the same entry-state/next-state rule, so the public run performs exactly two issue operations.

Run once to confirm your predicted incorrect sequence. Then make the smallest possible change to the returned value. Do not remove or duplicate the write: the action side of the ActionValue contract is not defective. Run again and explain why the first result and the first committed next state differ by one.

Observable completion contract

  • Starting at 40, consecutive calls return 40 and 41 in that order.
  • Each execution advances next exactly once, so the states after those calls are 41 and 42.
  • For any entry value n, the result denotes n while the following call observes the advanced state.
  • The function remains an executable ActionValue; replacing it with a pure value or an Action does not satisfy the interface.

Progressive hints

Hint 1 — separate the two products

Write down the value contract and the state-transition contract independently. Only one of them disagrees with the required trace.

Hint 2 — identify the observed state

A register read after a scheduled write in the same atomic action still sees the entry state. Textual order does not expose the pending update.

Hint 3 — narrow the edit

The existing assignment already computes the next state. The return expression should describe the ticket owned by the current call, not recompute that assignment's right-hand side.

Transfer experiment

In a scratch copy after completion, change the state step from one to two while preserving “return current, then advance.” Predict the first two results and states before running. This separates the entry-state rule from the particular increment amount. Restore the original step before submitting.

Review this concept
Ready
Main.bsv