Creating a Stack Frame

You need to create a stack frame for a function if the function:

To create a stack frame, use the fralloc directive at the beginning of your function and the frfree directive just before the blr statement. The directive fralloc automatically allocates (while ffree automatically de-allocates) memory for local variables, and saves and restores the register contents.

Listing 1. Example of creating a stack frame
asm void red ()
{
  fralloc
  // Your code here
  frfree
  blr
}

The fralloc directive has an optional argument, number, that lets you specify the size, in bytes, of the parameter area of the stack frame. The stack frame is an area for storing parameters used by the assembly code. The compiler creates a 0-byte parameter area for you to pass variables into your assembly language functions.

Function arguments are passed using registers. If your assembly-language routine calls any function that requires more parameters than will fit into registers r3 to r10 and fp1 to fp8 , you need to pass that size to fralloc . In the case of integer values, registers r3 - r10 are used. For floating-point values, registers fp1 - fp8 are used.

As an example, if you pass 12 values of type long integer to your assembly function, this would consume 16 bytes of the parameter area. Registers r3 - r10 will hold eight integers, leaving 4 byte integers in the parameter area.