0
0
ARM Architectureknowledge~5 mins

Parameter passing in registers in ARM Architecture

Choose your learning style9 modes available
Introduction

Passing parameters in registers helps the processor work faster by avoiding slower memory access. It makes function calls quicker and more efficient.

When a function needs to receive input values quickly.
When optimizing code for speed on ARM processors.
When writing low-level code like assembly or embedded systems.
When the number of parameters is small enough to fit in registers.
When following ARM calling conventions for interoperability.
Core Concept
ARM Architecture
r0, r1, r2, r3 are used to pass the first four parameters to a function.

Only the first four parameters are passed in registers; others go on the stack.

Registers r0 to r3 are general-purpose registers reserved for parameter passing.

Key Points
Passing two integer parameters 5 and 10 in registers r0 and r1 before calling a function.
ARM Architecture
MOV r0, #5
MOV r1, #10
BL add_function
Passing four parameters using registers r0 to r3.
ARM Architecture
MOV r0, #1
MOV r1, #2
MOV r2, #3
MOV r3, #4
BL process_four_params
Passing first four parameters in registers and the fifth parameter on the stack (using r4 and push).
ARM Architecture
MOV r0, #1
MOV r1, #2
MOV r2, #3
MOV r3, #4
MOV r4, #5
PUSH {r4}
BL function_with_five_params
Detailed Explanation

This program passes two numbers (7 and 3) in registers r0 and r1 to a function that adds them. The result is returned in r0.

ARM Architecture
; Simple ARM assembly example passing two parameters

MOV r0, #7      ; First parameter = 7
MOV r1, #3      ; Second parameter = 3
BL add_numbers  ; Call function

; Function add_numbers
add_numbers:
    ADD r0, r0, r1  ; Add parameters in r0 and r1, store result in r0
    BX lr           ; Return to caller
OutputSuccess
Important Notes

Registers r0 to r3 are volatile and can be overwritten by called functions.

Additional parameters beyond four are passed on the stack in memory.

Return values are usually passed back in r0.

Summary

Parameters are passed using registers r0 to r3 for speed.

Only the first four parameters fit in registers; others use the stack.

This method follows ARM's standard calling convention for efficient function calls.