0
0
Embedded Cprogramming~10 mins

Startup sequence and reset vector in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Startup sequence and reset vector
Power ON / Reset
CPU Fetches Reset Vector
Jump to Startup Code
Initialize Data & BSS Sections
Call main() Function
Program Runs Normally
When the device powers on or resets, the CPU fetches the reset vector address, jumps to startup code that sets up memory, then calls main() to start the program.
Execution Sample
Embedded C
void Reset_Handler() {
  // Initialize data and bss
  main();
}

int main() {
  // User code
  while(1) {}
}
This code shows the reset handler initializing memory then calling main, which runs the main program loop.
Execution Table
StepActionAddress/ValueDescription
1Power ON or ResetN/ADevice powers on or reset signal triggers
2Fetch Reset Vector0x00000000CPU reads reset vector address from fixed location
3Jump to Reset_Handler0x00000000CPU jumps to startup code address
4Initialize .data sectionCopy from Flash to RAMVariables with initial values are copied
5Zero .bss sectionSet to 0Uninitialized variables are cleared
6Call main()0x00000100Start main program function
7Execute main loopN/AProgram runs user code in infinite loop
8EndN/AProgram runs indefinitely until reset or power off
💡 Program runs indefinitely in main loop; no exit from startup sequence
Variable Tracker
VariableStartAfter Step 4After Step 5After Step 6Final
.data sectionIn FlashCopied to RAMUnchangedUnchangedIn RAM with initial values
.bss sectionUndefinedUndefinedZeroedUnchangedZero in RAM
Program Counter (PC)Reset Vector AddressReset_Handler AddressReset_Handler Addressmain() Addressmain() Address
Key Moments - 3 Insights
Why does the CPU jump to the reset vector address after power on?
Because the reset vector holds the address of the startup code, so the CPU knows where to begin executing after reset (see execution_table step 2 and 3).
What happens to variables in the .bss section during startup?
They are set to zero to ensure no garbage values (see execution_table step 5 and variable_tracker .bss section).
Why does main() never return in embedded programs?
Because embedded programs usually run continuously, main() contains an infinite loop to keep the program running (see execution_table step 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the CPU doing at step 4?
AInitializing the .data section by copying from Flash to RAM
BJumping to main() function
CZeroing the .bss section
DFetching the reset vector
💡 Hint
Check the 'Action' and 'Description' columns at step 4 in execution_table
According to variable_tracker, what is the state of the .bss section after step 5?
ACopied to RAM with initial values
BUndefined
CZeroed in RAM
DContains garbage values
💡 Hint
Look at the .bss section row under 'After Step 5' in variable_tracker
If the reset vector address changed, which step in execution_table would be directly affected?
AStep 7: Execute main loop
BStep 2: Fetch Reset Vector
CStep 5: Zero .bss section
DStep 4: Initialize .data section
💡 Hint
The reset vector address is fetched at step 2 according to execution_table
Concept Snapshot
Startup sequence in embedded C:
- On reset, CPU fetches reset vector address
- CPU jumps to startup code (Reset_Handler)
- Startup code initializes .data and .bss sections
- Then calls main() function
- main() runs user code, usually infinite loop
- Reset vector is fixed address pointing to startup code
Full Transcript
When an embedded device powers on or resets, the CPU starts by fetching the reset vector address from a fixed memory location. This address points to the startup code, often called Reset_Handler. The CPU jumps to this startup code, which initializes the memory sections: it copies initialized variables (.data) from Flash to RAM and clears uninitialized variables (.bss) by setting them to zero. After memory setup, the startup code calls the main() function, where the user's program runs, usually inside an infinite loop to keep the device running. This sequence ensures the program starts correctly every time the device resets or powers on.