1. Entry Phase

The Handoff:
Entering the C World

You have power. You have a stack. Your RAM is zeroed and ready. There is only one thing left to do: Pass the baton to the user's code.

asm _reset_handler
int main(void)

1. The Final Branch Instruction

In the assembly startup file (usually titled startup_stm32.s or similar), the very last instruction of the initialization process is a "Jump" or "Branch" instruction.

bl main // Branch with Link to 'main'

2. What if main() ends?

In a standard computer program (like a Python script), the program finishes and you go back to the terminal. But in a Microcontroller, there is nowhere to go back to.

If main() ever finishes, the CPU would continue executing random uninitialized memory—resulting in a catastrophic crash. To prevent this, the startup assembly usually has an "Infinite Loop" trap right after the branch:

_exit_trap:
  b _exit_trap    ; Hang here forever if main exits
Why "Zero to Zero"? We started with a system that had Zero instructions running, and we ended with an application that is (hopefully) running in a Zero-error state. The "Booting" process is the bridge between these two states.

Congratulations!

You've mastered the internal journey of a Microcontroller from power-on to application entry.

Return to Syllabus Hub →