Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Insert a packed bit field

Hardware interview practice

Insert a packed bit field

MediumBit ManipulationSystemVerilog

Replace bits [hi:lo] of a 32-bit word with the low bits of field while preserving all other bits.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
x = 32'h0000_A55A, field = 4'h3, hi = 7, lo = 4
Expected output
32'h0000_A53A

The nibble mask clears bits [7:4] before the new packed field is ORed into that position.

What to cover

Requirements

  1. Require indices that satisfy 0 <= lo <= hi <= 31.
  2. Create a mask covering hi through lo, inclusive.
  3. Clear the destination region before inserting the shifted field.
  4. Handle a full-width [31:0] field without shifting a 32-bit value by 32.
asic.fyi · Learn silicon end to end.info@asic.fyi