0
0
Embedded Cprogramming~5 mins

Startup sequence and reset vector in Embedded C - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Startup sequence and reset vector
O(n)
Understanding Time Complexity

We want to understand how the time it takes for a microcontroller to start up changes as the startup code runs.

Specifically, how does the startup sequence and reset vector affect execution time as the program begins?

Scenario Under Consideration

Analyze the time complexity of the following embedded C startup code snippet.


void Reset_Handler(void) {
    // Copy initialized data from flash to RAM
    for (int i = 0; i < DATA_SIZE; i++) {
        data_ram[i] = data_flash[i];
    }

    // Zero initialize the BSS section
    for (int i = 0; i < BSS_SIZE; i++) {
        bss_ram[i] = 0;
    }

    main();
}
    

This code runs after reset. It copies data and clears memory before calling main.

Identify Repeating Operations

Look at the loops that repeat work.

  • Primary operation: Two for-loops copying and clearing memory.
  • How many times: Each loop runs once, repeating DATA_SIZE and BSS_SIZE times respectively.
How Execution Grows With Input

As the size of data to copy and clear grows, the time grows too.

Input Size (DATA_SIZE + BSS_SIZE)Approx. Operations
10About 20 operations (copy + clear)
100About 200 operations
1000About 2000 operations

Pattern observation: The time grows roughly in direct proportion to the total size of data to initialize.

Final Time Complexity

Time Complexity: O(n)

This means the startup time grows linearly with the amount of data to copy and clear.

Common Mistake

[X] Wrong: "The startup time is always constant no matter how much data is initialized."

[OK] Correct: The loops copy and clear memory based on data size, so more data means more work and longer time.

Interview Connect

Understanding how startup code scales helps you write efficient embedded programs and shows you know how hardware initialization affects performance.

Self-Check

"What if the startup code used DMA (Direct Memory Access) to copy data instead of a loop? How would the time complexity change?"