<?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>why does this assembly fail?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25470/why-does-this-assembly-fail</link><description> 
Hello, 

 
I have this C code 

 
int value_a, value_b ;
value_a = value_b ;
 

 
that translates to this assembly: 

 
0x0002B128 E58D600C STR R6,[R13,#0x000C]
 

 
but the assignment fails - both variables are allocated on the
stack. if I allocate</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/114929?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 23:34:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a38b2399-ac98-4afb-b529-7298cc1738eb</guid><dc:creator>Marius Cosa</dc:creator><description>&lt;p&gt;&lt;p&gt;
ok I understand. thanks for your help.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/103102?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 12:53:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:97106a62-d2ff-494d-bd2a-b6c3d4174a96</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;it might fail,&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You&amp;#39;re still not making any sense. Either it fails, or it doesn&amp;#39;t.
So which is it?&lt;/p&gt;

&lt;p&gt;
You&amp;#39;ve been asked what exactly went wrong. Now please look at your
answer again and tell us: does that look like you fulfilled that
request?&lt;/p&gt;

&lt;p&gt;
As others have said, this looks like you&amp;#39;re basing your idea of
what it means for code like this to &amp;quot;fail&amp;quot; on incorrect assumptions
about what a C compiler is required to make of your source code. Just
because you define and initialize a variable doesn&amp;#39;t mean the
compiled code has to perform that initialization. And even if it is
performed, it may happen at an unexpected time.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/103089?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 05:04:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1df653ab-91d6-49d1-8a94-e908ddc4ba37</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;value_d and value_f are initialized to 0, the others
not!&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The compiler is not required to do everything that&amp;#39;s stated in the
source code. If variables are never used, the compiler is free to
ignore them.&lt;/p&gt;

&lt;p&gt;
You may want to try to lower the optimization settings, or declare
variables as volatile, if you want the compiler to follow your code
more rigorously.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/77439?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 04:57:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b4524602-fb2c-43da-96b9-64ef7c25c0af</guid><dc:creator>Marius Cosa</dc:creator><description>&lt;p&gt;&lt;p&gt;
sorry for the incomplete explanation. the variable &amp;quot;value_b&amp;quot; is
initialized. even if I do something like this (with another
variable):&lt;/p&gt;

&lt;pre&gt;
int value_c = 0
&lt;/pre&gt;

&lt;p&gt;
it might fail, hence filling the variable with what I regard as
garbage. this only happens if R13 is involved.&lt;/p&gt;

&lt;p&gt;
actually, I have this code:&lt;/p&gt;

&lt;pre&gt;
int   value_c = 0,
                 value_d = 0,
                 value_e = 0,
                 value_f = 0,
&lt;/pre&gt;

&lt;p&gt;
value_d and value_f are initialized to 0, the others not!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/56056?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 04:53:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:68a3d58d-01a4-40bd-957f-cc08dff8b808</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;but the assignment fails - both variables are allocated on the
stack.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
What exactly &amp;quot;fails&amp;quot;, and how? What result would you expect?&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;if I allocate the target variable in RAM (say, using &amp;quot;static&amp;quot;)
it works.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The stack is in RAM, too.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/56055?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 04:52:32 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3f88bf0a-c5e2-4ed7-9ee3-c6bfa9884ff6</guid><dc:creator>Stefan Hartwig</dc:creator><description>&lt;p&gt;&lt;p&gt;
What do you expect the statement is doing?&lt;br /&gt;
The variables aren&amp;#39;t initialzed, thus the values are
unpredictable.&lt;/p&gt;

&lt;p&gt;
Maybe the compiler just &amp;quot;cut-optimizes&amp;quot; the call.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: why does this assembly fail?</title><link>https://community.arm.com/thread/56057?ContentTypeID=1</link><pubDate>Tue, 12 May 2009 04:51:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ad134ef1-35b4-419f-a81a-4a285f4b0575</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
That can&amp;#39;t be the complete C code, since there is no assign of an
initial value to value_b.&lt;/p&gt;

&lt;p&gt;
When you declare the variables &amp;#39;static&amp;#39;, they will be
zero-initialized before main() is called.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>