Keil Logo

Function Parameters

C functions pass up to five parameters in registers (R8-R12). Bit parameters are passed in R15. Parameters that do not fit into R8-R12 are passed on the user stack and are accessed using [R0+#disp] instructions.

The following examples demonstrate the C166 parameter passing conventions:

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

The above function has one argument that easily fits into a single 16-bit register (R8).

void func2 (
  int b,        /* 1st parameter passed in R8  */
  int c,        /* 2nd parameter passed in R9  */
  int near *d,  /* 3rd parameter passed in R10 */
  char e,       /* 4th parameter passed in R11 */
  char f)       /* 5th parameter passed in R12 */

The above function has five arguments. All fit into R8-R12.

void func3 (
  long g,       /* 1st parameter passed in R8/R9   */
  int far *h,   /* 2nd parameter passed in R10/R11 */
  int i,        /* 3rd parameter passed in R12     */
  long j)       /* 4th parameter cannot be located in registers */

The above function has four arguments. The first three use all available registers. The fourth argument must be passed on the user stack.

void func4 (
  double k,     /* 1st parameter passed in R8/R9/R10/R11 */
  long j)       /* 2nd parameter LSW passed in R12 */
                /* MSW passed on the user stack */

The above function has two arguments. The first argument uses four of the five registers. The LSW of the second argument is passed in R12 and the MSW is passed on the user stack.

void func5 (
  bit m,               /* 1st parameter passed in R15.0 */
  bit n)               /* 2nd parameter passed in R15.1 */

The above function has two bit arguments that passed in R15.

void func6 (
  char o,       /* 1st parameter passed in R8    */
  bit p,               /* 2nd parameter passed in R15.0 */
  char q,       /* 3rd parameter passed in R9    */
  bit r)               /* 4th parameter passed in R15.1 */

The above function has four arguments (two are bits) that are passed in registers and in R15 (for the bits).

  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.