ARM Technical Support Knowledge Articles

ACCESSING GLOBAL VARIABLES DEFINED IN C CODE

Applies to: A251 Macro Assembler

Answer


Information in this article applies to:


QUESTION

I have the following global variable defined in my C code. How can I access it from assembly code?

char data send_it _at_ 0x07;

ANSWER

Use the following line in your assembly code. It is the equivalent of a C 'extern' declaration for the global variable:

EXTRN         DATA : BYTE (send_it)

You can easily determine what the equivalent assembler code is for your C code by getting the compiler to generate the assembler for you. For example, to find out the assembler required for the extern declaration you could write the following C source file:

#pragma src
extern char data send_it _at_ 0x07;

void main(void)
{
  send_it = 7;
}

The assignment is included to prevent the optimizer from removing the variable access.

Compiling this file generates an .src file which contains the equivalent assembler code. Looking at the variable declarations in this file shows how to declare the 'extern' in C and access the global variable.

MORE INFORMATION

Article last edited on: 2005-07-15 12:53:55

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential