Keil™, An ARM® Company

Technical Support

C51: ACCESSING ASSEMBLY VARIABLES FROM C


Information in this article applies to:

  • C51 Version 5.xx
  • C51 Version 6.xx

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);
}

Last Reviewed: Monday, December 18, 2000


Did this article provide the answer you needed?
 
Yes
No
Not Sure