Crossware

Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->In-Line Assembler Code->Accessing Global Variables

Global variables can be directly accessed by name from within the assembler code.  The compiler adds an underscore to all global variable names.  Therefore the programmer should add an underscore to enable access from assembler.

To access a global variable, you need to load its address into an address register:

char nGlobal;

int get_byte()
{
#asm
ldr r0, =_nGlobal                    
ldr r0, [r0]
#endasm
}

Using the _asm syntax, the compiler will add the underscore for you:

char nGlobal;

int get_byte()
{
    _asm(    ldr r0, ={nGlobal});
    _asm(    ldr r0, [r0]);
}