SystemVerilog #61 · 2026-11-23 · Indexed part-selects · Easy · about 15 min

Pick and patch a field

Write field_slice: a combinational block that reads and writes fields of a 32-bit word w with variable positions.

  • ext is nibble n of w. Nibble 0 is bits [3:0], nibble 7 is bits [31:28].
  • ins is w with nibble n replaced by d. All other bits are unchanged.
  • top is byte j of w counted from the top: j = 0 is bits [31:24], j = 3 is bits [7:0].

Example with w = 32'h76543210: n = 3 gives ext = 3. With d = A, ins = 76 54 A2 10. j = 1 gives top = 54.

Fill in field_slice.sv. Run tries three cases.

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