Hardware interview practice
Code an asynchronously reset register with enable
Write parameterized RTL for a register that samples data when enable is high, holds its value otherwise, and asserts reset asynchronously low.
Starting point
Question code
module enabled_register #(
parameter int W = 8
) (
input logic clk,
input logic rst_n,
input logic en,
input logic [W-1:0] d,
output logic [W-1:0] q
);Reviewed example
Work through one case
Input
W=8; rst_n=1, en=1, d=8'h5A at a rising clock edgeExpected output
q=8'h5A after the nonblocking updateWith reset inactive and enable asserted, the edge samples d into q. If enable were low, q would retain its prior value.
What to cover
Requirements
- Assert reset on negedge rst_n without waiting for a clock edge.
- Model normal reset release behavior at the next posedge clk.
- Hold q when en is low.
- Use nonblocking assignments for q.
