<?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 strange bit variable code generation in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183621#M6311</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;hello&lt;BR /&gt;I have&amp;nbsp;C code like this&lt;BR /&gt;#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE&lt;BR /&gt;...&lt;BR /&gt;struct {&lt;BR /&gt;u8 one:1;&lt;BR /&gt;u8 two:1&lt;BR /&gt;}alm;&lt;BR /&gt;#pragma DATA_SEG DEFAULT_RAM&lt;BR /&gt;&lt;BR /&gt;void fun1(void)&lt;BR /&gt;{&lt;BR /&gt;...&lt;BR /&gt;alm.one = alm.two;&lt;BR /&gt;alm.one = PTAD_PTAD0;&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;and CW translate fun1 to:&lt;BR /&gt;&lt;BR /&gt;343: alm.one = alm.two;&lt;BR /&gt;0000 020003 [5] BRSET 1,alm,L6 ;abs = 0006&lt;BR /&gt;0003 1100 [5] BCLR 0,alm&lt;BR /&gt;0005 65 [3] SKIP2 L8 ;abs = 0008&lt;BR /&gt;0006 L6:&lt;BR /&gt;0006 1000 [5] BSET 0,alm&lt;BR /&gt;0008 L8:&lt;BR /&gt;344: alm.one = PTAD_PTAD0;&lt;BR /&gt;0008 b600 [3] LDA _PTAD&lt;BR /&gt;000a a401 [2] AND #1&lt;BR /&gt;000c 2603 [3] BNE L11 ;abs = 0011&lt;BR /&gt;000e 1100 [5] BCLR 0,alm&lt;BR /&gt;0010 65 [3] SKIP2 L13 ;abs = 0013&lt;BR /&gt;0011 L11:&lt;BR /&gt;0011 1000 [5] BSET 0,alm&lt;BR /&gt;0013 L13:&lt;BR /&gt;&lt;BR /&gt;my question is why PTAD_PTAD0 is not same as alm.two?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Jan 2008 17:03:40 GMT</pubDate>
    <dc:creator>rg</dc:creator>
    <dc:date>2008-01-29T17:03:40Z</dc:date>
    <item>
      <title>strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183621#M6311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;hello&lt;BR /&gt;I have&amp;nbsp;C code like this&lt;BR /&gt;#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE&lt;BR /&gt;...&lt;BR /&gt;struct {&lt;BR /&gt;u8 one:1;&lt;BR /&gt;u8 two:1&lt;BR /&gt;}alm;&lt;BR /&gt;#pragma DATA_SEG DEFAULT_RAM&lt;BR /&gt;&lt;BR /&gt;void fun1(void)&lt;BR /&gt;{&lt;BR /&gt;...&lt;BR /&gt;alm.one = alm.two;&lt;BR /&gt;alm.one = PTAD_PTAD0;&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;and CW translate fun1 to:&lt;BR /&gt;&lt;BR /&gt;343: alm.one = alm.two;&lt;BR /&gt;0000 020003 [5] BRSET 1,alm,L6 ;abs = 0006&lt;BR /&gt;0003 1100 [5] BCLR 0,alm&lt;BR /&gt;0005 65 [3] SKIP2 L8 ;abs = 0008&lt;BR /&gt;0006 L6:&lt;BR /&gt;0006 1000 [5] BSET 0,alm&lt;BR /&gt;0008 L8:&lt;BR /&gt;344: alm.one = PTAD_PTAD0;&lt;BR /&gt;0008 b600 [3] LDA _PTAD&lt;BR /&gt;000a a401 [2] AND #1&lt;BR /&gt;000c 2603 [3] BNE L11 ;abs = 0011&lt;BR /&gt;000e 1100 [5] BCLR 0,alm&lt;BR /&gt;0010 65 [3] SKIP2 L13 ;abs = 0013&lt;BR /&gt;0011 L11:&lt;BR /&gt;0011 1000 [5] BSET 0,alm&lt;BR /&gt;0013 L13:&lt;BR /&gt;&lt;BR /&gt;my question is why PTAD_PTAD0 is not same as alm.two?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2008 17:03:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183621#M6311</guid>
      <dc:creator>rg</dc:creator>
      <dc:date>2008-01-29T17:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183622#M6312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello,&lt;BR /&gt;could you check/publish here the the declaration of &lt;FONT size="2"&gt;PTAD_PTAD0?&lt;BR /&gt;Maybe this is not a bitfield, or signed?&lt;BR /&gt;&lt;BR /&gt;BK&lt;BR /&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2008 17:13:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183622#M6312</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2008-01-29T17:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183623#M6313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Do I misunderstand something ("&lt;FONT size="2"&gt;my question is why PTAD_PTAD0 is not same as alm.two" )&lt;/FONT&gt;? This code do not try to set the port pin equal to alm.two, only sets alm.one equal to the port pin!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2008 20:35:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183623#M6313</guid>
      <dc:creator>Sten</dc:creator>
      <dc:date>2008-01-29T20:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183624#M6314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;There are a lot of things which might cause different code patterns to be generated for bitfields.&lt;BR /&gt;Just the ones which come to my mind now:&lt;BR /&gt;- the number of bits (both times the same in your snippet)&lt;BR /&gt;- the bit offset, especially bitoffsets 0 and 7 (least/most significant bits) may have special patterns&lt;BR /&gt;- if the bitfield is volatile (I guess the &lt;FONT size="2"&gt;PTAD_PTAD0 is)&lt;BR /&gt;- how the bitfield is used, especially tests, assignments, ...&lt;BR /&gt;- note that all your assignments have two bitfield accesses.&lt;BR /&gt;- how to access the variables (DIRECT,...)&lt;BR /&gt;- surrounding code (CSE, reuse of previously used computed subexpressions, available constants, common code opti, ...)&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2008 22:11:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183624#M6314</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-01-29T22:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183625#M6315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;Sten wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Do I misunderstand something ("&lt;FONT size="2"&gt;my question is why PTAD_PTAD0 is not same as alm.two" )&lt;/FONT&gt;? This code do not try to set the port pin equal to alm.two, only sets alm.one equal to the port pin!&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT face="Century"&gt;No, you are right.&amp;nbsp; They are putting putting the value in alm.two into alm.one and then overwriting it with the status of&amp;nbsp;&lt;FONT size="2"&gt;PTAD_PTAD0.&lt;/FONT&gt;&amp;nbsp; If they want&amp;nbsp;&lt;FONT size="2"&gt;PTAD_PTAD0&lt;/FONT&gt; to be equal to&amp;nbsp;alm.two they have to either:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;1) &lt;FONT size="2"&gt;Have&amp;nbsp;PTAD_PTAD0&amp;nbsp;as an output then change the second line to&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;EM&gt;PTAD_PTAD0 = alm.one;&lt;/EM&gt;&amp;nbsp; // Set Port D Bit 0 to alm.one&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;or 2) Do the following:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&lt;FONT size="2"&gt;alm.one = PTAD_PTAD0; // Set Port D Bit 0 to alm.one&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;alm.two = alm.one;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set alm.two to alm.one&lt;/FONT&gt;&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by allawtterb on &lt;SPAN class="date_text"&gt;2008-01-29&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:25 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2008 04:23:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183625#M6315</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-01-30T04:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183626#M6316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I did understand the OP's question as why the compiler would generate different code for the two assignments, and not why the values of the port and the alm.two bitfield member were not the same. The latter are of course not the same as they are completely independent.&lt;BR /&gt;&lt;BR /&gt;rg, can you clarify?&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2008 07:25:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183626#M6316</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-01-30T07:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: strange bit variable code generation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183627#M6317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;thanks replies.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;this snippet is for testing OPTION of compiler,&lt;BR /&gt;and dont have real effect.&lt;BR /&gt;in fact,I want asm code like this:&lt;BR /&gt;&amp;nbsp;BRSET 1,alm,L6&lt;BR /&gt;&amp;nbsp;BCLR 0,alm&lt;BR /&gt;&amp;nbsp;BRA L8&lt;BR /&gt;L6:&lt;BR /&gt;&amp;nbsp;BSET 0,alm&lt;BR /&gt;L8:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;BRSET 0,_PTAD,L61&lt;BR /&gt;&amp;nbsp;BCLR 0,alm&lt;BR /&gt;&amp;nbsp;BRA L81&lt;BR /&gt;L61:&lt;BR /&gt;&amp;nbsp;BSET 0,alm&lt;BR /&gt;L81:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Feb 2008 01:11:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/strange-bit-variable-code-generation/m-p/183627#M6317</guid>
      <dc:creator>rg</dc:creator>
      <dc:date>2008-02-17T01:11:50Z</dc:date>
    </item>
  </channel>
</rss>

