Embedded Systems Fundamentals · Interview question

What happens between reset and the first line of main()?

A strong answer

On a Cortex-M, reset is hardware-minimal: the core reads the first two words of the vector table at the start of flash, word 0 is loaded into the stack pointer (it's a data value, the initial SP), and word 1 is the reset handler's address, loaded into the PC, so execution begins in the reset handler. The reset handler is the startup code that prepares the C runtime: it copies the initialized-global section (.data) from its load image in flash into its run location in SRAM, zeroes the uninitialized-global section (.bss), typically calls a SystemInit to set up clocks/FPU and the vector table offset, runs C library init and any C++ static constructors, and finally calls main. If main ever returns, the startup code traps in an infinite loop because there's nowhere to return to on bare metal. So by the time main runs, the stack is valid and all globals hold their correct initial values, none of which you wrote, but all of which your program assumes.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Boot Sequence & Startup Code

Everything that runs before main(): the reset vector, copying .data and zeroing .bss, the vector table, and how a bootloader hands off via VTOR.

More Boot Sequence & Startup Code questions

Browse all 472 interview questions
What happens between reset and the first line of main()? | EmbeddedPrep.io