Challenge - 5 Problems
Register Watcher Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of register value after bitwise operation
What is the output of the following code that manipulates a hardware register value?
Embedded C
volatile unsigned char REG = 0x3C; REG |= 0x05; printf("0x%X", REG);
Attempts:
2 left
💡 Hint
Remember that |= sets bits that are 1 in the mask without clearing others.
✗ Incorrect
The original value 0x3C (00111100) OR 0x05 (00000101) results in 00111101 which is 0x3D.
❓ Predict Output
intermediate2:00remaining
Value of register after clearing bits
What will be the value of REG after clearing bits 0 and 1 using bitwise AND?
Embedded C
volatile unsigned char REG = 0xFF; REG &= ~0x03; printf("0x%X", REG);
Attempts:
2 left
💡 Hint
Use bitwise NOT on 0x03 to clear bits 0 and 1.
✗ Incorrect
0x03 is 00000011, ~0x03 is 11111100. AND with 0xFF clears bits 0 and 1, resulting in 0xFC.
🔧 Debug
advanced2:00remaining
Identify the error in register assignment
What error will this code cause when trying to assign a value to a hardware register?
Embedded C
volatile unsigned char *REG = 0x40021000; *REG = 0xFF;
Attempts:
2 left
💡 Hint
Check the pointer assignment syntax for hardware registers.
✗ Incorrect
Assigning an integer directly to a pointer variable without casting causes a compilation error.
❓ Predict Output
advanced2:00remaining
Result of shifting register bits
What is the output of this code that shifts bits in a register?
Embedded C
volatile unsigned char REG = 0x0F; REG = REG << 2; printf("0x%X", REG);
Attempts:
2 left
💡 Hint
Left shift moves bits to higher positions, filling with zeros on the right.
✗ Incorrect
0x0F is 00001111. Shifting left by 2 bits gives 00111100 which is 0x3C.
🧠 Conceptual
expert2:00remaining
Why use volatile keyword with hardware registers?
Why is the volatile keyword important when declaring variables that map to hardware registers?
Attempts:
2 left
💡 Hint
Think about how the compiler treats variables that can change outside program control.
✗ Incorrect
Volatile tells the compiler the value can change anytime, so it must not optimize away accesses.