Q162FreeSystemVerilog
Reverse a physical bus at the lane boundary
Interview prompt
Question
A board routes a peripheral bus in reverse bit order. Build a parameterized combinational adapter whose output bit i is input bit W - 1 - i.
Candidate starting point
Implementation scaffold
module bit_reverse_adapter #(
parameter int unsigned W = 32
) (
input logic [W-1:0] in_bus,
output logic [W-1:0] out_bus
);
always_comb begin : reverse_bits
// TODO: Implement reverse_bits using the supplied state and interface.
end
endmoduleReviewed example
Trace one case
Input
W=8; input=8'b1101_0010Expected output
output=8'b0100_1011Output bit i is wired directly from input bit 7-i, making this a bit reversal rather than a byte-endian conversion.
What to cover
Requirements
- Treat this as bit reversal, not a byte swap or numeric endian conversion.
- Support every static width W >= 1, including odd widths and W = 1.
- Drive every output bit on every evaluation and infer no state.
- Use only compile-time-bounded, synthesizable wiring.
