Skip to content
code0.HDL

47Implementation

Map writes into imported RTL

The broken boundary

mkRegisterWriter already calls the imported register's write method, but the editable mapWrite function changes the value before it reaches that boundary. The starter compiles and runs, so this is a data-path defect rather than a BVI syntax error. The stored value shown by mkTop does not match the value requested by its load call.

Only repair the editable mapping. The interfaces, wrapper, BVI declaration, and mkTop are part of the supplied integration contract.

Read and predict before editing

Trace one value in this order:

  1. mkTop calls writer.load with an 8-bit value.
  2. mkRegisterWriter.load applies mapWrite.
  3. ImportedReg.write maps the result to RTL port D_IN; EN marks the call.
  4. The later read exposes the value stored by the external register.

Before Run, predict whether the starter will fail compilation or complete with the wrong displayed value. Then explain which single editable declaration can account for that observation. The BVI mapping is intact: the defect is the typed value supplied to it.

Minimal repair and completion

Preserve the Bit#(8) -> Bit#(8) function type and make the mapping preserve every requested bit pattern. Do not change call order or recreate the imported register.

Run the program after the edit. Completion is observable when the value shown after load equals that call's input, including values whose bits are not all zero. Reason about why the repair works: the function changes neither width nor meaning, and the immutable Action method still controls D_IN and EN.

Progressive hints

Hint 1: identify the contract

The wrapper needs an identity data mapping. No clock, reset, or schedule change is involved.

Hint 2: narrow the location

Compare the argument and result of mapWrite. Which one contains the caller's eight requested bits before the imported method is invoked?

Hint 3: choose the smallest edit

Change only the function's result expression so it depends directly on its existing argument; no conversion or new state is needed.

Transfer experiment

After completing the task, change the value passed by mkTop to a pattern with both high and low bits, such as 8'ha5, and predict the display before Run. The same mapping should preserve the new pattern without another code change.

Review this concept
Ready
Main.bsv