Keil Logo

Global Variables

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:

EXTERN DATA(jim)

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:

MOV A,jim

Note

  • Type information is not transmitted to your assembler routines. Assembly code must explicitly know the type of the global variable and the order in which it is stored.
  • The EXTERN definitions for a C external variable are generated only if the variable is referenced by the C code in the module. If an external variable is only referenced by in-line assembly code, you must declare them in in-line assembly code within that module.

Related Knowledgebase Articles

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.