<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Code generation bug? in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Code-generation-bug/m-p/159707#M4328</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having weird problems with CW4.7 for HC12. I am compiling some code from an older project, and I think the compiler may be generating the wrong code. Here's a snippet along with what the compiler generates (well, at least what the debugger assembly window shows):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// get a pointer from a const array, (p is allocated to Y)&lt;/P&gt;&lt;P&gt;p = ArrayAddresses[n];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // clra; asld; tfr d,x; ldy 37083,X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// copy value pointed to into some static variable&lt;/P&gt;&lt;P&gt;temp0 = *p;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ldd 0,y; std 0x0907&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// now, here is the problem as I see it...&lt;/P&gt;&lt;P&gt;*pRam = *p;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ldd 2,y+; ldx 5,sp; std 0,x, sty 0,sp&lt;/P&gt;&lt;P&gt;p++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The compiler generates "ldd 2,y+", which is the correct postincrement, but it should access 0,y instead of 2,y shouldn't it? Or am I missing something? I thought ldd 2,y+ loads D with the word pointed to by y+2, and then increments y. The target is a B32 derivative, if that makes any difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The postincrement seems to be throwing the compiler off, because if I drop the final p++, it generates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*pRam = *p &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ldd 0,y; ldx 5,sp; std 0,x&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, I am having problems with code in the form *ptr++. I haven't tried switching any optimisations off yet, I wanted to check if this is a known problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oliver&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Oliver on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-09&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:39 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Mar 2009 06:33:14 GMT</pubDate>
    <dc:creator>Oliver</dc:creator>
    <dc:date>2009-03-09T06:33:14Z</dc:date>
    <item>
      <title>Code generation bug?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Code-generation-bug/m-p/159707#M4328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having weird problems with CW4.7 for HC12. I am compiling some code from an older project, and I think the compiler may be generating the wrong code. Here's a snippet along with what the compiler generates (well, at least what the debugger assembly window shows):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// get a pointer from a const array, (p is allocated to Y)&lt;/P&gt;&lt;P&gt;p = ArrayAddresses[n];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // clra; asld; tfr d,x; ldy 37083,X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// copy value pointed to into some static variable&lt;/P&gt;&lt;P&gt;temp0 = *p;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ldd 0,y; std 0x0907&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// now, here is the problem as I see it...&lt;/P&gt;&lt;P&gt;*pRam = *p;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ldd 2,y+; ldx 5,sp; std 0,x, sty 0,sp&lt;/P&gt;&lt;P&gt;p++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The compiler generates "ldd 2,y+", which is the correct postincrement, but it should access 0,y instead of 2,y shouldn't it? Or am I missing something? I thought ldd 2,y+ loads D with the word pointed to by y+2, and then increments y. The target is a B32 derivative, if that makes any difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The postincrement seems to be throwing the compiler off, because if I drop the final p++, it generates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*pRam = *p &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ldd 0,y; ldx 5,sp; std 0,x&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, I am having problems with code in the form *ptr++. I haven't tried switching any optimisations off yet, I wanted to check if this is a known problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oliver&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Oliver on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-09&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:39 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2009 06:33:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Code-generation-bug/m-p/159707#M4328</guid>
      <dc:creator>Oliver</dc:creator>
      <dc:date>2009-03-09T06:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Code generation bug?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Code-generation-bug/m-p/159708#M4329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; ldd 2,y+&lt;/P&gt;&lt;P&gt;Loads 0,y and then increments y by 2 (Post increment)&lt;/P&gt;&lt;P&gt;&amp;gt; ldd 2,+y&lt;/P&gt;&lt;P&gt;Increments y by 2 and then load D the location y points too after the increment (pre increment).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the HC12 instruction set supports both, if the + is after the register, the register is post incremented and the access is at the previous register value. If the + is before the register, the register is preincremented and the location the new register value refers is accessed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See "3.8.5 Auto Pre/Post Decrement/Increment Indexed Addressing" in the CPU12 reference manual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2009 09:31:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Code-generation-bug/m-p/159708#M4329</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-03-09T09:31:19Z</dc:date>
    </item>
  </channel>
</rss>

