Interfacing C with Assembly Language
6-20
When using only the 'C5x: if your assembly routine does not change the
NDX bit of status register PMST from 0 to 1, then the INDX register
shadows AR0; preserving AR0 preserves INDX as well. If your routine
does change the NDX bit, then both AR0 and INDX must be preserved
explicitly.
If you change any of the status register fields for which Table 6−2 on page
-
6-11 shows a presumed value, you must ensure that value is restored. Be
especially careful that you ensure that the ARP is AR1.
Interrupt routines must save all the registers they use. (For more informa-
-
tion, see section 6.5, Interrupt Handling, on page 6-25.)
When you call a C function from assembly language, push any arguments
-
onto the stack in reverse order. Pop them off after calling the function.
When you call C functions, remember that only the dedicated registers
-
listed above are preserved. C functions can change the contents of any
other register.
Longs and floats are stored in memory with the least significant word at
-
the lower address.
Functions must return values in the accumulator. 16-bit integer values and
-
pointers must be loaded in the accumulator with proper sign extension.
No assembly module should use the .cinit section for any purpose other
-
than autoinitialization of global variables. The C startup routine in boot.c
assumes that the .cinit section consists entirely of initialization tables.
Disrupting the tables by putting other information in .cinit causes unpre-
dictable results.
The compiler adds an underscore ( _ ) to the beginning of all identifiers
-
(that is, labels). In assembly language modules, you must use an under-
score prefix for all objects that are to be accessible from C. For example,
a C object named x is called _x in assembly language. Identifiers that are
used only in assembly language modules can use any name that does not
begin with an underscore without conflicting with a C identifier.
Any object or function declared in assembly language that is accessed or
-
called from C must be declared with the .global directive in the assembler.
This declares the symbol as external and allows the linker to resolve refer-
ences to it.
Likewise, to access a C function or object from assembly language,
declare the C object with .global. This creates an undeclared external
reference that the linker resolves.
Need help?
Do you have a question about the TMS320C2x and is the answer not in the manual?