Parameter passing in registers in ARM Architecture - Time & Space 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.
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.
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.
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) |
|---|---|
| 1 | 1 |
| 3 | 3 |
| 4 | 4 |
| 5 | 4 (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.
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.
[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.
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.
What if the architecture allowed passing eight parameters in registers instead of four? How would the time complexity change?