Variable definition: The variables that are accessed by both C and assembly routines
must be defined as global variables using the directive .global, .def, or .ref by the
Compiler mode: By using the C compiler, the C55x CPL (compiler mode) bit is
automatically set for using stack-pointer (SP) relative addressing mode when entering
an assembly routine. The indirect addressing modes are preferred under this configur-
ation. If we need to use direct addressing modes to access data memory in a C callable
assembly routine, we must change to DP (data-page) direct addressing mode. This can
be done by clearing the CPL bit. However, before the assembly routine returns to its C
caller function, the CPL bit must be restored. The bit clear and bit set instructions,
bclr CPL and bset CPL, can be used to reset and set the CPL bit in the status register
ST1, respectively. The following code can be used to check the CPL bit, turn CPL bit off
if it is set, and restore the CPL bit before returning it to the caller.
btstclr #14, *(ST1), TC1 ; Turn off CPL bits if it is set
(more instructions . . . )
xcc continue, TC1
; TC1 is set if we turned CPL bit off
; Turn CPL bit on
Passing arguments: To pass arguments from a C function to an assembly routine, we
must follow the strict rules of C-callable conversions set by the C compiler. When
passing an argument, the C compiler assigns it to a particular data type and then places
it in a register according to its data type. The C55x C compiler uses the following three
classes to define the data types:
Data pointer: int *, or long *.
16-bit data: char, short, or int.
32-bit data: long, float, double, or function pointers.
If the arguments are pointers to data memory, they are treated as data pointers. If the
argument can fit into a 16-bit register such as int and char, it is considered to be 16-bit
data. Otherwise, it is considered 32-bit data. The arguments can also be structures. A
structure of two words (32 bits) or less is treated as a 32-bit data argument and is passed
using a 32-bit register. For structures larger than two words, the arguments are passed
by reference. The C compiler will pass the address of a structure as a pointer, and this
pointer is treated like a data argument.
For a subroutine call, the arguments are assigned to registers in the order that the
arguments are listed in the function. They are placed in the following registers according
to their data type, in an order shown in Table 2.6.
Note in Table 2.6 the overlap between AR registers used for data pointers and the
registers used for 16-bit data. For example, if T0 and T1 hold 16-bit data arguments,
and AR0 already holds a data pointer argument, a third 16-bit data argument would be
placed into AR1. See the second example in Figure 2.13. If the registers of the appro-
priate type are not available, the arguments are passed onto the stack. See the third
example in Figure 2.13.
MIXED C AND ASSEMBLY LANGUAGE PROGRAMMING