0
0
ARM Architectureknowledge~5 mins

Why subroutines enable modular assembly code in ARM Architecture - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why subroutines enable modular assembly code
O(n)
Understanding Time Complexity

When using subroutines in ARM assembly, we want to understand how the program's running time changes as we reuse code blocks.

We ask: How does calling subroutines affect the total steps the processor takes?

Scenario Under Consideration

Analyze the time complexity of this ARM assembly code using a subroutine.


    MOV R0, #5          
    BL  subroutine      
    MOV R1, R0          
    
subroutine:
      ADD R0, R0, #1    
      BX  LR            
    

This code calls a subroutine that adds 1 to a value and returns it.

Identify Repeating Operations

Look for repeated instructions or calls.

  • Primary operation: The subroutine call (BL) and return (BX LR).
  • How many times: Once in this example, but could be many times if called repeatedly.
How Execution Grows With Input

If the subroutine is called multiple times, the total steps grow with the number of calls.

Input Size (calls)Approx. Operations
10About 10 subroutine calls plus main instructions
100About 100 subroutine calls plus main instructions
1000About 1000 subroutine calls plus main instructions

Pattern observation: The total steps increase roughly in direct proportion to how many times the subroutine is called.

Final Time Complexity

Time Complexity: O(n)

This means the total running time grows linearly with the number of subroutine calls.

Common Mistake

[X] Wrong: "Calling a subroutine adds no extra time because it's just a jump."

[OK] Correct: Each call and return takes extra steps, so more calls mean more total time.

Interview Connect

Understanding how subroutines affect execution time helps you write clear, reusable code while knowing its performance impact.

Self-Check

"What if the subroutine called itself recursively? How would that change the time complexity?"