How a Function Makes a Call

A function (parent function) performs the following tasks when it calls another function (child function).

  1. Arguments passed to a function are placed in registers or on the stack.
  2. A function (parent function) performs the following tasks when it calls another function (child function):

    If arguments are passed to a function, up to the first ten arguments are placed in registers A4, B4, A6, B6, A8, B8, A10, B10, A12, and B12. If longs, long longs, doubles, or long doubles are passed, they are placed in register pairs A5:A4, B5:B4, A7:A6, and so on.

    The C6600 __x128_t type object is aligned to a 64-bit or 128-bit boundary. (See the note in Section 8.6.2.) However, for C6600, if multiple __x128_t arguments are passed, the next __x128_t argument is passed in the first available quad, where the list of available quads has the ordering: A7:A6:A5:A4, B7:B6:B5:B4, A11:A10:A9:A8, B11:B10:B9:B8. If there are no more available quads, the __x128_t goes onto the stack. A subsequent 32-bit, 40-bit, or 64-bit argument can take the first available register or register pair even if an earlier __x128_t argument has been put on the stack.

    Any remaining arguments are placed on the stack (that is, the stack pointer points to the next free location; SP + offset points to the eleventh argument, and so on, assuming for C6600 an __x128_t is not passed.) Arguments placed on the stack must be aligned to a value appropriate for their size. An argument that is not declared in a prototype and whose size is less than the size of int is passed as an int. An argument that is a float is passed as double if it has no prototype declared.

    A structure argument is passed as the address of the structure. It is up to the called function to make a local copy.

    For a function declared with an ellipsis indicating that it is called with varying numbers of arguments, the convention is slightly modified. The last explicitly declared argument is passed on the stack, so that its stack address can act as a reference for accessing the undeclared arguments.

    Figure 8-1 shows the register argument conventions.

  3. The calling function must save registers A0-A9, B0-B9, A16-A31, and B16-B31 if their values are needed after the call. It should do this by pushing the values onto the stack. See Section 3.2 of the C6000 Embedded Application Binary Interface Application Report (SPRAB89A) for details about register conventions.
  4. The caller (parent) calls the function (child).
  5. Upon returning, the caller reclaims any stack space needed for arguments by adding to the stack pointer. This step is needed only in assembly programs that were not compiled from C/C++ code. This is because the C/C++ compiler allocates the stack space needed for all calls at the beginning of the function and deallocates the space at the end of the function.
Figure 8-1 Register Argument ConventionsTMS320C6000 register_args_pru187.gif