Consider this simplified embedded C startup code snippet. What will be printed when the microcontroller resets?
#include <stdio.h> void Reset_Handler(void) { printf("System Reset\n"); main(); } int main(void) { printf("Main Application Started\n"); return 0; }
Think about the order in which functions are called during reset.
The Reset_Handler prints "System Reset" then calls main(), which prints "Main Application Started". So the output is both lines in that order.
Choose the best description of the reset vector's role in an embedded system.
Think about what happens immediately after powering on or resetting the device.
The reset vector is a fixed memory location that contains the address of the first instruction the CPU executes after reset.
What error will this embedded C startup code cause when the microcontroller resets?
void Reset_Handler(void) {
main();
}
int main(void) {
// Application code
return 0;
}
void Reset_Handler(void);Look carefully at the function declarations and definitions.
The last line redeclares Reset_Handler as a function prototype after its definition, causing a duplicate declaration error.
In embedded systems, the reset vector is often defined in the linker script. Which of these linker script snippets correctly sets the reset vector to the start of Reset_Handler?
The ENTRY command sets the program start address.
ENTRY(Reset_Handler) sets the reset vector to Reset_Handler. The .text section contains code.
Given this startup code, how many instructions are executed before main() starts?
void Reset_Handler(void) {
// 1
init_data(); // 2
init_bss(); // 3
SystemInit(); // 4
main(); // 5
}
void init_data(void) { /* copies initialized data */ }
void init_bss(void) { /* clears zero data */ }
void SystemInit(void) { /* sets up clocks */ }
int main(void) {
return 0;
}Count the function calls before main() inside Reset_Handler.
Before main(), four instructions run: the comment line is not an instruction, but the three init functions plus the call to Reset_Handler itself count as instructions. The question asks for instructions before main(), so only the three init calls plus the Reset_Handler entry count as four.