Complete the code to define a hardware register at address 0x4000.
volatile unsigned int* reg = (volatile unsigned int*) [1];The hardware register is located at memory address 0x4000, so we cast that address to a pointer.
Complete the code to write the value 0xFF to the hardware register.
*reg = [1];Writing 0xFF sets all bits in the register to 1, often enabling all features.
Fix the error in the code to read the value from the hardware register correctly.
unsigned int value = [1];Dereferencing the pointer with *reg reads the value stored at the hardware register address.
Fill in the blank to set bit 3 of the register without changing other bits.
*reg = *reg [1] (1 << 3);
To set a specific bit without affecting other bits, use the bitwise OR operator (|) with a mask where only that bit is set: (1 << 3).
Fill in the blanks to clear bit 2 and set bit 5 of the register.
*reg = (*reg [1] (1 << 2)) [2] (1 << 5);
First, clear bit 2 using AND with the negated mask (& ~ (1 << 2)), then set bit 5 using OR with (1 << 5).