ARM Technical Support Knowledge Articles

ACCESSING ASSEMBLY VARIABLES FROM C

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I need to create variables in my assembly code and access them from C. How do I do that?

ANSWER

It's best to create separate C and assembly modules. Then, you can create an extern variable declaration in the C module for the assembly variable. For example:

Assembly Code

PUBLIC MY_VAR

?CO?JUNK1 SEGMENT CODE
RSEG ?CO?JUNK1

my_var:   db   "This is a test", 00

END

C Code

#include <string.h>

extern char code my_var [];

void main (void)
{
char buf [21];

strcpy (buf, my_var);

while (1);
}

Article last edited on: 2000-12-18 00:00:00

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