Your question is Hardware Register Bit Operations. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In embedded code for Google Pixel device drivers, low-level register access often requires changing individual bits without affecting the rest of the register. Implement a function that processes a sequence of bit operations on an unsigned register value.
Write a function that takes an initial integer register, a register width width, and a list of operations. Each operation is one of:
("set", bit)("clear", bit)("toggle", bit)("read", bit)For each read operation, record whether the target bit is 0 or 1. Return the final register value and the list of read results.
Bit positions are 0-indexed from the least significant bit. All updates must stay within the lower width bits.
set, clear, toggle, readdef process_register_ops(register, width, operations):