0
0
ARM Architectureknowledge~5 mins

If-else implementation in assembly in ARM Architecture - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: If-else implementation in assembly
O(1)
Understanding Time Complexity

Analyzing time complexity helps us understand how the execution time changes when running an if-else in assembly.

We want to know how the number of steps grows as the input or conditions change.

Scenario Under Consideration

Analyze the time complexity of the following ARM assembly code implementing an if-else.


    CMP R0, #0       
    BEQ else_label   
    MOV R1, #1      
    B end_if        
else_label:       
    MOV R1, #0      
end_if:
    

This code compares a value and sets another register based on the condition.

Identify Repeating Operations

Look for repeated steps or loops.

  • Primary operation: Single comparison and branch instructions.
  • How many times: Each instruction runs once per execution; no loops or repeated traversals.
How Execution Grows With Input

The number of instructions executed stays almost the same regardless of input size.

Input Size (n)Approx. Operations
106 instructions
1006 instructions
10006 instructions

Pattern observation: Execution steps do not increase with input size; they remain constant.

Final Time Complexity

Time Complexity: O(1)

This means the time to run the if-else does not grow as the input changes; it stays constant.

Common Mistake

[X] Wrong: "If-else in assembly takes longer when the input value is bigger."

[OK] Correct: The instructions run once regardless of input size; the condition only changes which path runs, not how many steps.

Interview Connect

Understanding that simple conditional branches run in constant time helps you explain how decisions affect program speed clearly and confidently.

Self-Check

"What if the if-else was inside a loop running n times? How would the time complexity change?"