Consider this embedded C code snippet initializing an interrupt vector table. What will be the output when the reset_handler is called?
#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; }
Look at which function is called from the vector table index 0.
The first element in the interrupt vector table is reset_handler. Calling interrupt_vector_table[0]() executes reset_handler, which prints "System Reset".
Choose the correct description of an interrupt vector table in embedded systems.
Think about what the processor needs to do when an interrupt occurs.
The interrupt vector table contains the addresses of interrupt service routines (ISRs). When an interrupt occurs, the processor uses this table to find and jump to the correct ISR.
Examine the following code snippet. What error will occur when compiling?
void reset_handler(void) {}
void nmi_handler(void) {}
void (*interrupt_vector_table[])(void) = {
reset_handler,
nmi_handler,
};Check if trailing commas are allowed in array initializers in C.
In C, trailing commas in array initializers are allowed. The code declares an array of function pointers correctly and compiles without error.
Given this embedded C code with a default interrupt handler, what will be printed when interrupt_vector_table[2]() is called?
#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; }
Look at the function pointer at index 2 in the vector table.
The third element (index 2) in the vector table points to default_handler, which prints "Default Interrupt Handler".
Given this embedded C code snippet, how many entries does the interrupt_vector_table array contain?
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
};Count the number of functions listed inside the initializer braces.
The array is initialized with three function pointers: reset_handler, nmi_handler, and hard_fault_handler. So, it contains 3 entries.