Interfacing C with Assembly Language
6-23
Run-Time Environment
6.4.3 Accessing Assembly Language Variables From C Code
It is sometimes useful for a C program to access variables defined in assembly
language. Accessing uninitialized variables from the .bss section or from a
named section is straightforward:
1) Use the .bss or .usect directive to define the variable.
2) Use the .global directive to make the definition external.
3) Precede the name with an underscore in assembly language.
4) In C, declare the variable as extern, and access it normally.
3 shows how you can access a variable defined in .bss.
Example 6
−
3. Accessing a Variable Defined in .bss From C
(a) C program
extern int var;
/* External variable
*/
var = 1;
/* Use the variable
*/
(b) Assembly language program
* Note the use of underscores in the following lines
.bss
_var,1
; Define the variable
.global
_var
; Declare it as external
You may not always want a variable to be in the .bss section. A common situa-
tion is a lookup table defined in assembly language that you do not want to put
in RAM. In this case, you must define a pointer to the object and access it indi-
rectly from C.
You must first define the object. It is helpful, but not necessary, to put it in its
own initialized section. Declare a global label that points to the beginning of
the object, and then the object can be linked anywhere into the memory space.
To access it in C, you must declare the object as
extern
and not precede it with
an underscore. Then you can access the object normally.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...