Skip to content
code0.HDL

38Implementation

Sequence two FSM steps

Goal and current behavior

orderedSteps must describe two dependent actions: establish a register value of three, then add four in a later FSM step. The starter returns a sequence containing only noAction, so the controller can finish without changing the register. A successful compile is therefore not evidence that the intended process ran.

Before editing, predict the public simulation: start from value == 0, account for the placeholder step, and decide which value the finish rule will observe.

Navigate the starter

Read starter/Main.bsv in this order:

  1. Find orderedSteps and its Reg#(UInt#(8)) argument. This function is the editable control description.
  2. Mark the seq ... endseq boundaries and the current noAction statement.
  3. Follow the returned Stmt into mkFSM inside mkTop.
  4. Notice that start launches once and finish observes value only after controller.done.

Keep the function signature and the supplied mkTop module unchanged. The repair belongs inside the returned statement, not in the observation logic.

Reason about the minimal repair

The two operations are dependent. If the later addition is to read three, the write of three must commit at a clock boundary before that addition is evaluated. Preserve the existing sequence and replace the placeholder with the smallest number of action statements that creates those two commit points. Do not replace the process with one assignment of the final constant: that would produce a sample value without demonstrating ordered FSM behavior.

After editing, predict the state trace before selecting Run:

  • initial idle state: value is 0;
  • after the first action commits: value is 3 and the FSM still has work;
  • after the following action commits: value is 7;
  • only then may the finish rule observe a completed controller.

Observable completion contract

The repair is complete when the public run terminates with value equal to 7 and the value arose from two ordered state transitions. The second action must read the first action's committed register state. The controller must not collapse the dependent work into a single step, stall, or report completion before both writes have committed.

Progressive hints

Hint 1: identify the language contract

Separate action statements in seq execute in source order, with a commit boundary between FSM steps.

Hint 2: narrow the repair location

Only the placeholder inside orderedSteps needs replacement. The controller and its start/finish rules already expose the right observation point.

Hint 3: choose the shape of the actions

Use one register assignment to establish the base value and a later assignment that derives its value by reading the register. Avoid precomputing the terminal constant.

Transfer experiment

After the required version works, temporarily reverse the two action statements without changing either expression. Predict the intermediate and terminal states, then Run. This isolates source ordering from arithmetic and shows why a seq is part of the data dependency. Restore the required order before grading.

Review this concept
Ready
Main.bsv