<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using a C-variable from ASM</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/38322/using-a-c-variable-from-asm</link><description> 
Hey guys I see there are numerous threads and support docs with
mixing C + ASM. but I am still pulling hair out. I can get C to use a
register I declared in asm 
eg: 

 
 CODLO DATA 39D 

 
by using 

 
 extern unsigned char CODLO; 
in c 

 
but I found</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Using a C-variable from ASM</title><link>https://community.arm.com/thread/114833?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2009 02:41:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:121233dc-e45c-49b5-847d-d8efa9fef566</guid><dc:creator>Xarion Comoretto</dc:creator><description>&lt;p&gt;&lt;p&gt;
My ASM and c still seem to be fighting with one another, another
variable I have declared in C is being overwritten by the ASM code. I
have followed the docs you posted to me (&lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;
it says ....&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
To access these variables in assembler, you must create an extern
declaration that matches the original declaration. For
example:&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;EXTERN DATA(jim)&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
if I do that it does not compile and i get the errors in my
original post..&lt;/p&gt;

&lt;p&gt;
so what I have done now, I have declared the register in ASM :&lt;/p&gt;

&lt;p&gt;
CODHI DATA 41D CH_REG DATA 40D CODLO DATA 39D&lt;/p&gt;

&lt;p&gt;
and then at the top i put&lt;/p&gt;

&lt;p&gt;
PUBLIC CODHI&lt;br /&gt;
PUBLIC CODLO&lt;br /&gt;
PUBLIC CH_REG&lt;/p&gt;

&lt;p&gt;
and in the c i put:&lt;/p&gt;

&lt;p&gt;
extern unsigned char CODHI ;&lt;br /&gt;
extern unsigned char CH_REG;&lt;br /&gt;
extern unsigned char CODLO ;&lt;/p&gt;

&lt;p&gt;
this gives me the problem with the variables being overwritten. I
have no idea where to turn from here :(&lt;/p&gt;

&lt;p&gt;
thanx again&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a C-variable from ASM</title><link>https://community.arm.com/thread/103032?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2009 11:12:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e11971b9-9e24-4c37-b2f9-08c8593335a9</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;if i assign a register a name in ASM does the compiler know not
to use that memory location for other c variables?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No, it won&amp;#39;t. The aspects of mixing C and assembly routines are
described, in great detail (far greater than anything that could be
described in a posting here), in the compilers manual. This includes
things like calling conventions and register usage.&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a C-variable from ASM</title><link>https://community.arm.com/thread/77339?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2009 08:54:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1f65dd3e-9788-4ae9-b220-522eaf2e74e4</guid><dc:creator>Xarion Comoretto</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Christoph,&lt;/p&gt;

&lt;p&gt;
thanx for the reply, if i assign a register a name in ASM does the
compiler know not to use that memory location for other c variables?
should i declare all my registers i use in my asm file as public
?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using a C-variable from ASM</title><link>https://community.arm.com/thread/55829?ContentTypeID=1</link><pubDate>Thu, 09 Apr 2009 04:18:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:27a0cad5-f0d1-4172-a9d6-97099e637e88</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Hey guys I see there are numerous threads and support docs with
mixing C + ASM. but I am still pulling hair out.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
What you&amp;#39;re looking for is in the C51 compiler manual. No need to
look for any other docs.&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>