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
Coding & Algorithms
Software Engineer
Intel
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Bit masks and shifts
Read-modify-write
Memory-mapped I/O
Input validation
Register layouts
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions