RTL Design #61 · 2026-11-23 · Part-selects and sign extension · Easy · about 15 min

Byte-lane extract, insert and swap

Write lane_ops: a combinational block that works on the four byte lanes of a 32-bit word. Lane 0 is bits [7:0], lane 3 is bits [31:24]. sel picks the lane, and op picks what y is:

op y
0 the selected byte, zero-extended to 32 bits
1 the selected byte, sign-extended to 32 bits
2 word with the selected byte replaced by byte_in
3 word with the order of its four bytes reversed (sel and byte_in are ignored)

Example: with word = 32'h8899aa7f, sel 3: op 0 gives 32'h00000088, op 1 gives 32'hffffff88. With sel 1 and byte_in = 8'h12, op 2 gives 32'h8899127f. With word = 32'h11223344, op 3 gives 32'h44332211.

Fill in lane_ops.sv. Run tries five operations.

Write and run your answer in the browser. The hidden tests check it, and it’s free.