0
0
ARM Architectureknowledge~5 mins

Parameter passing in registers in ARM Architecture - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Parameter passing in registers
O(1)
Understanding Time Complexity

When a program calls a function, it often sends information called parameters. In ARM architecture, these parameters are passed using registers.

We want to understand how the time to pass parameters grows as the number of parameters increases.

Scenario Under Consideration

Analyze the time complexity of the following ARM code snippet that passes parameters in registers.


    MOV R0, param1
    MOV R1, param2
    MOV R2, param3
    BL  function_call
    

This code moves up to four parameters into registers R0 to R3 before calling a function.

Identify Repeating Operations

Look for repeated steps that take time.

  • Primary operation: Moving each parameter into a register (MOV instructions).
  • How many times: Once per parameter, up to four times.
How Execution Grows With Input

As the number of parameters increases, the number of MOV instructions grows linearly, but only up to four parameters.

Input Size (parameters)Approx. Operations (MOV instructions)
11
33
44
54 (only first 4 in registers)

Pattern observation: The number of operations grows linearly with parameters but stops at four because only four registers are used.

Final Time Complexity

Time Complexity: O(1)

This means the time to pass parameters in registers does not grow beyond a fixed small number, even if more parameters exist.

Common Mistake

[X] Wrong: "Passing more parameters always takes more time because each parameter adds a new instruction."

[OK] Correct: Only the first four parameters use registers, so after four, extra parameters are passed differently and do not add register moves.

Interview Connect

Understanding how parameters are passed in registers helps you explain efficient function calls and low-level performance, a useful skill in systems programming and embedded development.

Self-Check

What if the architecture allowed passing eight parameters in registers instead of four? How would the time complexity change?