Accessing ANSI-C variables in an assembly source file

A variable or constant defined in an ANSI-C source file is accessible in an assembly source file.

The variable or constant is defined in the ANSI-C source file using the standard ANSI-C syntax, as listed in the following listing:

Listing: Example definition of data and constants

unsigned int CData;        /* Definition of a variable */
unsigned const int CConst; /* Definition of a constant */

An external declaration for the variable or constant must be inserted into the assembly source file, as listed in the following listing:

This can also be done in a separate file, included in the assembly source file.

Listing: Example declaration of data and constants

XREF CData;  External declaration of a variable
XREF CConst; External declaration of a constant

The variables or constants can then be accessed in the usual way, using their names, as listed in the following listing:

Listing: Example of data and constant reference

           LDA CConst
         ....

           LDA CData

          ....
Note: The compiler supports also the automatic generation of assembler include files. See the description of the -La compiler option in the compiler manual.