Hardware interview practice
Insert a packed bit field
Replace bits [hi:lo] of a 32-bit word with the low bits of field while preserving all other bits.
Reviewed example
Work through one case
Input
x = 32'h0000_A55A, field = 4'h3, hi = 7, lo = 4Expected output
32'h0000_A53AThe nibble mask clears bits [7:4] before the new packed field is ORed into that position.
What to cover
Requirements
- Require indices that satisfy 0 <= lo <= hi <= 31.
- Create a mask covering hi through lo, inclusive.
- Clear the destination region before inserting the shifted field.
- Handle a full-width [31:0] field without shifting a 32-bit value by 32.
