Hardware interview practice
Build a parameterized N-to-1 multiplexer
Write a reusable combinational block that selects one W-bit word from N inputs when N does not have to be a power of two.
Starting point
Question code
parameter int N = 6;
parameter int W = 8;
input logic [N-1:0][W-1:0] data;
input logic [$clog2(N)-1:0] sel;
output logic [W-1:0] y;Reviewed example
Work through one case
Input
N = 6, W = 8, sel = 6Expected output
y = 8'h00The three-bit select can encode 0 through 7, leaving two unused codes, 6 and 7. Code 6 therefore takes the explicit invalid path.
What to cover
Requirements
- Return data[sel] for every select value below N.
- Return all zeros for an unused select code.
- Support every N >= 2 and W >= 1.
- Assign y completely and never evaluate an out-of-range array element.
