49Implementation
Set an imported RTL parameter
The elaboration defect
mkInitializedRegister constructs external RTL whose initial contents come
from a Verilog parameter. The frozen BVI declaration already maps its BSV
constructor argument to that parameter, but the editable constant supplies the
wrong argument. The starter therefore builds valid hardware with the wrong
initial state; this is not a runtime write failure.
Only the declaration of importedInitialValue is editable. Preserve its type,
the wrapper, BVI declaration, and mkTop.
Read and predict before editing
Follow the static path first:
importedInitialValue -> mkInitializedRegister -> mkImportedReg argument ->
RTL init parameter.
Then follow the runtime observation: mkTop.show calls imported.read before
performing any write. Before Run, predict whether the starter will compile and
which source declaration determines the displayed initial value. Distinguish
the constructor choice made while hardware is elaborated from read, which
only observes the resulting instance at runtime.
Minimal repair and completion
Set the editable 8-bit constant to represent the required hexadecimal initial
state, 2a. Do not alter the BVI parameter assignment or add an initialization
rule.
After Run, the first read must show the requested initial state without any
preceding write call. A correct repair explains both phases: changing the
constant selects a differently parameterized RTL instance at build time, while
the method protocol and runtime wiring stay unchanged.
Progressive hints
Hint 1: identify the phase
The value reaches a BVI parameter statement, so it configures the generated
instance rather than being driven on a data port each cycle.
Hint 2: find the editable source
Locate the only editable Bit#(8) declaration and trace where the immutable
wrapper passes it as a constructor argument.
Hint 3: preserve representation
Use an 8-bit hexadecimal literal for the requested 2a bit pattern. No method
body or rule needs to change.
Transfer experiment
After completing the task, choose a different 8-bit initial pattern and predict the first read. This experiment requires rebuilding the design: a parameter is fixed per generated instance and cannot be changed by a later method call.