Interfacing C with Assembly Language
6-19
Run-Time Environment
6.4 Interfacing C with Assembly Language
The following are ways to use assembly language with C code:
-
Use separate modules of assembled code and link them with compiled C
modules (see section 6.4.1,
Using Assembly Language Modules With C
Code
). This is the most versatile method.
-
Use inline assembly language, embedded directly in the C source (see
section 6.4.2,
Using Inline Assembly Language
-
Use assembly language variables in C source (see section 6.4.3,
Access-
ing Assembly Language Variables From C
-
Modify the assembly language code that the compiler produces (see sec-
tion 6.4.4,
Modifying Compiler Output
6.4.1 Using Assembly Language Modules With C Code
Interfacing C with assembly language functions is straightforward if you follow
the calling conventions defined in section 6.3,
Function Structure and Calling
Conventions
, on page 6-14 and the register conventions defined in section
Register Conventions,
on page 6-9. C code can access variables and call
functions defined in assembly language, and assembly code can access C
variables and call C functions.
Follow these guidelines to interface assembly language and C:
-
All functions, whether they are written in C or assembly language, must
follow the register conventions outlined in section 6.2,
Register Conven-
tions
-
You must preserve any dedicated registers modified by a function. Dedi-
cated registers include:
AR0 (FP)
AR1 (SP)
AR6
AR7
INDX (TMS320C5x only)
If you use the stack normally, you do not need to explicitly preserve the SP.
In other words, you are free to use the stack inside a function as long as
you pop everything you pushed before your function exits.
You can use all other registers freely used without preserving their con-
tents.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...