0
0
Embedded Cprogramming~20 mins

Interrupt vector table in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interrupt Vector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this interrupt vector table initialization?

Consider this embedded C code snippet initializing an interrupt vector table. What will be the output when the reset_handler is called?

Embedded C
#include <stdio.h>

void reset_handler() {
    printf("System Reset\n");
}

void nmi_handler() {
    printf("NMI Interrupt\n");
}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,  // Reset vector
    nmi_handler     // NMI vector
};

int main() {
    interrupt_vector_table[0]();
    return 0;
}
ANMI Interrupt
BRuntime error: segmentation fault
CSystem Reset
DCompilation error due to missing semicolon
Attempts:
2 left
💡 Hint

Look at which function is called from the vector table index 0.

🧠 Conceptual
intermediate
1:30remaining
Which statement correctly describes the interrupt vector table?

Choose the correct description of an interrupt vector table in embedded systems.

AIt stores addresses of interrupt service routines and is used by the processor to jump to the correct handler.
BIt is a table that holds the priority levels of interrupts but not their addresses.
CIt is a memory area where all interrupt data is stored during execution.
DIt is a list of all interrupts that have occurred since system start.
Attempts:
2 left
💡 Hint

Think about what the processor needs to do when an interrupt occurs.

🔧 Debug
advanced
2:00remaining
What error occurs in this interrupt vector table declaration?

Examine the following code snippet. What error will occur when compiling?

Embedded C
void reset_handler(void) {}
void nmi_handler(void) {}

void (*interrupt_vector_table[])(void) = {
    reset_handler,
    nmi_handler,
};
AError: incompatible types in assignment to function pointer array.
BError: missing 'const' qualifier for the vector table pointer.
CError: trailing comma in the initializer list is not allowed in C.
DNo error; code compiles successfully.
Attempts:
2 left
💡 Hint

Check if trailing commas are allowed in array initializers in C.

Predict Output
advanced
2:00remaining
What is the output of this vector table with a default handler?

Given this embedded C code with a default interrupt handler, what will be printed when interrupt_vector_table[2]() is called?

Embedded C
#include <stdio.h>

void reset_handler() {
    printf("Reset Handler\n");
}

void default_handler() {
    printf("Default Interrupt Handler\n");
}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,
    default_handler,
    default_handler
};

int main() {
    interrupt_vector_table[2]();
    return 0;
}
AReset Handler
BDefault Interrupt Handler
CSegmentation fault at runtime
DCompilation error: initializer list size mismatch
Attempts:
2 left
💡 Hint

Look at the function pointer at index 2 in the vector table.

🚀 Application
expert
1:30remaining
How many entries are in this interrupt vector table array?

Given this embedded C code snippet, how many entries does the interrupt_vector_table array contain?

Embedded C
void reset_handler(void) {}
void nmi_handler(void) {}
void hard_fault_handler(void) {}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,
    nmi_handler,
    hard_fault_handler
};
A3
B2
C4
D1
Attempts:
2 left
💡 Hint

Count the number of functions listed inside the initializer braces.