Cx51 User's GuideCx51 Introduction Compiling Programs Language Extensions Preprocessor Advanced Programming Customization Files Startup Code Variable Initialization Code XBANKING.A51 Basic I/O Memory Allocation Optimizer Optimizer Options General Optimizations 8051-Specific Optimizations Global Register Coloring Segment Naming Conventions Data Objects Program Objects Parameters and Local Variables Interfacing C to Assembler Global Variables Function Parameters Passing in Memory Passing in Registers Function Return Values Using the SRC Directive Register Usage Overlaying Segments Small Model Example Compact Model Example Large Model Example Interfacing C programs to PL/M-51 Data Storage Formats Bit Variables 1-Byte Scalars 2-Byte Scalars 4-Byte Scalars Generic and Far Pointers Floating-point Numbers Floating-point Errors Absolute Memory Locations Absolute Access Macros Linker Location Controls The _at_ Keyword Debugging 8051 Derivatives Error Messages Library Reference Appendix
Global variables you create in your C programs are stored in the memory area specified or in the default memory area implied by the memory model. The assembly label for the variable is the variable name. For example, for the following global variables:
unsigned int bob; unsigned char jim;
the compiler generates the following assembler code:
?DT?MAIN SEGMENT DATA PUBLIC jim PUBLIC bob RSEG ?DT?MAIN bob: DS 2 jim: DS 1 ; unsigned int bob; ; unsigned char jim;
To access these variables in assembler, you must create an extern declaration that matches the original declaration. For example:
If you use in-line assembler, you may simply use C extern variable declarations to generate the assembler EXTERN declarations.
You may access global variables in assembler using their label names. For example:
Related Knowledgebase Articles
of your data.