Read and Write Named Bitfields in a 32-Bit Control Register
Last updated: November 29, 2026
Quick Overview
Given a register layout mapping field names to (least significant bit, width) and a list of (field, value) writes, apply the writes to a starting 32-bit register value without disturbing other bits, and support reading any field back.
Intel
November 29, 20260
0
0 solved
Given a register layout mapping field names to (least significant bit, width) and a list of (field, value) writes, apply the writes to a starting 32-bit register value without disturbing other bits, and support reading any field back.
Driver and firmware teams at Intel program hardware through memory-mapped registers where one 32-bit word packs enable bits, mode selects and divider values. A phone screen uses this to check that a candidate is fluent with masks and shifts and thinks about values that do not fit a field.
What the Interviewer Expects
- Builds the mask as ((1 << width) - 1) << lsb
- Clears the field before OR-ing in the new value (read-modify-write)
- Rejects values wider than the field instead of silently corrupting neighbors
- Keeps the result within 32 bits, including the top bit
- Explains why hardware writes often need read-modify-write and when write-1-to-clear bits break that pattern
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Some bits are write-1-to-clear status bits. How does that change read-modify-write?
- How would you make concurrent writers to the same register safe in a kernel driver?
- How would you express this layout in C, and why are C bitfield structs risky for hardware registers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Fields are described by (lsb, width) within a 32-bit register. Writes must change only the named field, values that do not fit must raise an error, and reads return the field shifted down to bit 0. ...
High-Level Design
A field is a contiguous run of bits, so one mask describes it: ((1 << width) - 1) << lsb. Reading is (reg & mask) >> lsb. Writing is read-modify-write: clear the field with reg & ~mask, then OR ...