Keil Logo

Function Parameters

C and C++ functions pass up to four parameters in registers R0-R3. The first parameter is passed in register R0. Parameters that cannot fit into registers are passed on the stack and are accessed using [SP+#displacement] instructions.

The following examples demonstrate the Keil CARM Compiler parameter passing conventions:

void func1 (
  char a)                   // 1st parameter passed in R0

The above function has one argument that is passed in R3.

void func2 (
  long  b,           // 1st parameter passed in R0
  int  *c,           // 2nd parameter passed in R1
  short d,           // 4th parameter passed in R2
  float e)           // 5th parameter passed in R3

The above function has four arguments. All fit into R0-R3.

void func3 (
  long long f,       // 1st parameter passed in R0/R1
  int g,             // 2nd parameter passed in R2
  double h)          // 3rd parameter passed in R3 & stack
  long i)            // 4th parameter passed only on stack

The above function has four arguments. The first two arguments are passed in registers. The third argument is passed only partly in registers. The fourth argument is passed on the stack.

struct val  {
  int arr[10];

struct val func4 (   // R0 holds destination address for struct return
  long j)            // 1st parameter passed in R1

The above function returns a structure (which is 10 bytes long) and uses all four registers R0-R3 to contain the structure contents.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.