1. Entry Phase

The Great Migration:
Flash to RAM

RAM is volatile. When you turn off the power, everything in RAM vanishes. When you turn it back on, RAM is filled with random garbage. But your code expects its global variables to be ready.

Flash (ROM)
Permanent Image
.data initial values
SRAM
Execution Space
Ready for C code

1. Moving the .data Section

Imagine you have a variable: int count = 10; defined globally. That value 10 is stored in Flash. But your CPU can't easily modify code in Flash. So, the Startup Code must manually copy that 10 into a specific address in RAM before main() starts.

2. Zeroing the .bss Section

What about int sensor_val;? C standards say it must start at zero. Instead of wasting space in Flash to store a bunch of zeros, the startup code simply finds the "BSS" region in RAM and runs a loop to fill it with zeros.

The Linker's Hidden Symbols

How does the startup code know where these sections start and end? The Linker Script provides special symbols like _sdata (Start of Data), _edata (End of Data), and _sbss. The assembly code uses these "Markers" to know exactly which bytes to move.

The final push...

Next: The Jump to main() →