<?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>KeilC51 can not compile this code correctly</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26782/keilc51-can-not-compile-this-code-correctly</link><description> 
hi: I have a code below: 

 
 char pop_value = 0X80;
 if(pop_value == 0X80)
 {
 pop_value = pop_value;//point 1

 }
 pop_value = pop_value;//point 2
 

 
I would have thought the code would jump to point 1 after logical
judge, but the simulating result</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/126377?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2010 12:02:34 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4ac25caf-2aba-4113-a7a1-fdad243a297a</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I have found the reason&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No, you haven&amp;#39;t. You haven&amp;#39;t found &lt;b&gt;anything&lt;/b&gt;. What you have
done so far is imagine things.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;or the compiler would produce wrong disassemble code.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
So you&amp;#39;ve been claiming all through this thread. And all that
while this judgement of yours has been based on incorrect assumptions
about what qualifies compiler output as correct.&lt;/p&gt;

&lt;p&gt;
I.e. you haven&amp;#39;t found anything, and you haven&amp;#39;t learned anything
either. Which begs the question why you&amp;#39;re even bothering to ask
questions, given that you couldn&amp;#39;t care less about the answers.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/130677?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2010 05:15:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1db14d55-6fc0-4c7d-8699-2754c17df8f2</guid><dc:creator>Bigtit Titchael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Read this and thought it must be 1st April.&lt;/p&gt;

&lt;p&gt;
Surely this is a [really rather poor] wind-up.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/126376?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2010 04:21:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8c820613-fecd-4a0b-9bb3-72c540b13741</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;the pop_value variable should be defined unsigned char type,or
the compiler would produce wrong disassemble code.But I do not
why?&lt;/i&gt;&lt;br /&gt;
the previous post said&amp;quot;&lt;br /&gt;
&lt;i&gt;So far: neither. The only thing you have demonstrated to be wrong
so far is your understanding of what the job of a C compiler
is.&lt;/i&gt;&lt;br /&gt;
now we can add&lt;br /&gt;
The other thing you have demonstrated to be wrong is your
understanding of C and the &amp;#39;51&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/116000?ContentTypeID=1</link><pubDate>Tue, 14 Sep 2010 17:53:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1222e87d-7f98-4f11-920a-2a7af5669184</guid><dc:creator>hero0765 maxwell</dc:creator><description>&lt;p&gt;&lt;p&gt;
hi: everybody,I have found the reason that the &lt;i&gt;pop_value&lt;/i&gt;
variable should be defined &lt;i&gt;unsigned char&lt;/i&gt; type,or the compiler
would produce wrong disassemble code.But I do not why?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/104232?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2010 15:07:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1ee1802a-999a-4844-9111-4d8dddf726d6</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;But I just want to know how to solve this problem or avoid this
error happening again&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You have not &lt;b&gt;shown&lt;/b&gt; us any problem worth solving, much less
an actual error!&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;how to change the keil compiler to produce correct assemble
language&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You don&amp;#39;t. Because it&amp;#39;s brutally obvious that you don&amp;#39;t know what
correct or incorrect assembly code is, in this context.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;My code has bug or the compiler&amp;#39;s wrong?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
So far: neither. The only thing you have demonstrated to be wrong
so far is your understanding of what the job of a C compiler is.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/136261?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2010 01:49:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:15fc62ae-690c-4916-9bdd-a66e34f76ae7</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
You may be right:&lt;/p&gt;

&lt;p&gt;
Level-0 (ie, minimum) optimisations are:&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;&lt;b&gt;Constant Folding:&lt;/b&gt; The compiler performs calculations
that reduce expressions to numeric constants, where possible. This
includes calculations of run-time addresses.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;&lt;b&gt;Simple Access Optimizing:&lt;/b&gt; The compiler optimizes access
of internal data and bit addresses in the 8051 system.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;&lt;b&gt;Jump Optimizing:&lt;/b&gt; The compiler always extends jumps to
the final target. Jumps to jumps are eliminated.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Level-1 optimisations are:&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;&lt;b&gt;Dead Code Elimination:&lt;/b&gt; Unused code fragments and
artifacts are eliminated.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;&lt;b&gt;Jump Negation:&lt;/b&gt; Conditional jumps are closely examined
to see if they can be streamlined or eliminated by the inversion of
the test logic.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_optimize.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_optimize.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/126388?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2010 00:47:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ab26eddf-c44e-4718-9bda-907dedd86543</guid><dc:creator>IB Shy</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t think it does - But may be wrong.&lt;/p&gt;

&lt;p&gt;
Many years ago, when I first looked into C compilers, the
one-to-one relationship appeared to be quite common and any form of
optimization was an extra.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/119064?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2010 00:39:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7d24cf65-e2bd-4a40-a97d-eb3c0fdbf47c</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Does setting the optimisation to minimum in C51 achieve that?&lt;/p&gt;

&lt;p&gt;
But do note that &lt;i&gt;&lt;b&gt;no&lt;/b&gt;&lt;/i&gt; &amp;#39;C&amp;#39; compiler is required to give
a 1:1 direct, in-sequence relationship between source code and
executable - that&amp;#39;s a fundamental principle of HLLs! If you want
that, then you have to write in Assembler!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/102276?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2010 00:32:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6ead62e2-b56e-451a-9893-99bf799244f6</guid><dc:creator>IB Shy</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;how to change the keil compiler to produce correct assemble
language.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
To overcome the situation you consider to be an error, I would
suggest that you find a compiler that is guaranteed to produce
totally non-optimised code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/104233?ContentTypeID=1</link><pubDate>Sun, 12 Sep 2010 21:41:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:56a98121-bd7b-428e-bdc9-f81b24c80fb7</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Start by finding an example where the compiler produces the wrong
code - and where you haven&amp;#39;t made too many assumptions about what the
compiler should do when you give it meaningless code to chew on.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/78622?ContentTypeID=1</link><pubDate>Sun, 12 Sep 2010 17:40:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0fb8b889-4a0f-45db-90ad-2f83a0027e28</guid><dc:creator>hero0765 maxwell</dc:creator><description>&lt;p&gt;&lt;p&gt;
hi: Thanks your advice. But I just want to know how to solve this
problem or avoid this error happening again.how to change the keil
compiler to produce correct assemble language .I found the keil
compiler produce wrong code sometime .It is associate with what
problem.My code has bug or the compiler&amp;#39;s wrong?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/126374?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 12:54:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:15c6e5b6-e6c7-4e56-aa88-2bb516e59d29</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;maybe not, but Keil, in their infinite wisdom, do all
optimizing in the linker&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;Not all --- not by a rather wide margin. I&amp;#39;m pretty sure none
of the linker-based optimazation are relevant to the example under
study. This should be optimized to nothing before the linker is even
run.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I still wonder why the making a switch an indirect jump instead of
a combersome calculation (when the state values are &amp;#39;organized&amp;#39;) is
not done in the compiler but in the linker&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/58636?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 11:28:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2cf268c1-dfb7-4cb0-898f-6a04d6f5f3d4</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I can not find the error happened.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Well, then how you do know there is an error to be found?&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;so I also compile this C code in another project.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No, you didn&amp;#39;t. That&amp;#39;s not the same code. For starters, &amp;#39;item&amp;#39; has
a different data type than &amp;#39;pop_value&amp;#39;.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;The important thing is that the compiler make a wrong logical
judge.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No. The important thing is for you to understand that you&amp;#39;re wrong
about what the compiler is required to do, and what it&amp;#39;s not. It&amp;#39;s
not required to compile that conditional instruction into any code at
all. And statements like&lt;/p&gt;

&lt;pre&gt;
item=item;
&lt;/pre&gt;

&lt;p&gt;
don&amp;#39;t do anything (unless &amp;#39;item&amp;#39; is volatile), so they can be
removed entirely.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/116001?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 11:11:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:13ada978-cff3-42de-ae11-0ece4f822886</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;maybe not, but Keil, in their infinite wisdom, do all
optimizing in the linker&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Not all --- not by a rather wide margin. I&amp;#39;m pretty sure none of
the linker-based optimazation are relevant to the example under
study. This should be optimized to nothing before the linker is even
run.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/104237?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 05:22:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9bb6b866-dcbc-463f-98a5-e9d7f12f8dd8</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Yes, but still not as smart as it should be. It should have
optimized away everything except the first line.&lt;/i&gt;&lt;br /&gt;
maybe not, but Keil, in their infinite wisdom, do all optimizing in
the linker.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/90617?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 00:18:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2bfe4bfa-daa8-4980-a3f1-22b83cde4edb</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Looks like that the compiler optimisation is smarter than the
programmer.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Yes, but still not as smart as it should be. It should have
optimized away everything except the first line. If the variable
&lt;b&gt;pop_value&lt;/b&gt; isn&amp;#39;t used anywhere in a non-trivial way, it should
have optimized away the first line too. Bottom line: the source code
should compile into nothing.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: KeilC51 can not compile this code correctly</title><link>https://community.arm.com/thread/58640?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2010 00:12:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:61f818f2-f164-4052-9f43-9013d0975d6a</guid><dc:creator>IB Shy</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;The important thing is that the compiler make a wrong logical
judge.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Looks like that the compiler optimisation is smarter than the
programmer.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>