0
0
Embedded Cprogramming~20 mins

Watching register values in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Register Watcher Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A0x39
B0x05
C0x38
D0x3D
Attempts:
2 left
💡 Hint
Remember that |= sets bits that are 1 in the mask without clearing others.
Predict Output
intermediate
2: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);
A0xFF
B0x03
C0xFC
D0x00
Attempts:
2 left
💡 Hint
Use bitwise NOT on 0x03 to clear bits 0 and 1.
🔧 Debug
advanced
2: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;
ARuntime error: segmentation fault
BCompilation error: incompatible types in assignment
CNo error, value 0xFF assigned correctly
DCompilation error: missing semicolon
Attempts:
2 left
💡 Hint
Check the pointer assignment syntax for hardware registers.
Predict Output
advanced
2: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);
A0x3C
B0x3F
C0xF0
D0x0F
Attempts:
2 left
💡 Hint
Left shift moves bits to higher positions, filling with zeros on the right.
🧠 Conceptual
expert
2:00remaining
Why use volatile keyword with hardware registers?
Why is the volatile keyword important when declaring variables that map to hardware registers?
AIt prevents the compiler from optimizing out reads and writes to the register
BIt makes the variable read-only
CIt initializes the register to zero automatically
DIt allows the variable to be used in interrupt service routines only
Attempts:
2 left
💡 Hint
Think about how the compiler treats variables that can change outside program control.