<?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 Long division Modulus Errors in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170272#M5192</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hello all,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have recently seen a problem where global variables have been clobbered when I get down to a "Long MODulo Unsigned" operation.&amp;nbsp; I have 5.7.0 CW IDE for HCS12 and have debugged down to the C implementation of&lt;/DIV&gt;&lt;DIV&gt;dword&amp;nbsp;n&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;n%10&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;the code works OK but TOTALLY CLOBBERS GLOBAL variables.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;actual code&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/**This routine converts numbers of type word to a string format of 0xXXXX===============================================================================**DESCRIPTION:***This routine converts numbers of type word to a string format of 0xXXXX in *decimal notation.*CALLING SEQUENCE:&amp;nbsp;&amp;nbsp; wordToDecStr(char *s, word n)**@param *s (character pointer of size + 1&amp;nbsp; or greater).@param n&amp;nbsp; (16 bit word to be converted).@param size&amp;nbsp; (char variable indicating number of leading zeros required).*\todo- List of things to do- Remove commented code*/void wordToDecStr(unsigned char *s, dword n,char size){ unsigned char i, j; dword temp; //return in error case if((size==0)) {&amp;nbsp;&amp;nbsp; return; }&amp;nbsp;&amp;nbsp;&amp;nbsp; //fill with character zeros for (j=0;j&amp;lt;size;j++) {&amp;nbsp; s[j] = '0'; } //modulus your way from the back to the front i=0; while ((n &amp;gt; 0)&amp;amp;&amp;amp;(size&amp;gt;i))&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=(n % 10) + '0'; ////&amp;lt;&amp;lt;&amp;lt;&amp;lt;ERROR OCCURS HERE&amp;nbsp; s[size-i-1] =(char)temp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n /= 10;&amp;nbsp; i++; }//end while s[size]='\0';//string terminator}//end wordToDecStr()&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does anybody have any experience with this?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:18:47 GMT</pubDate>
    <dc:creator>Emac</dc:creator>
    <dc:date>2020-10-29T09:18:47Z</dc:date>
    <item>
      <title>Long division Modulus Errors</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170272#M5192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hello all,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have recently seen a problem where global variables have been clobbered when I get down to a "Long MODulo Unsigned" operation.&amp;nbsp; I have 5.7.0 CW IDE for HCS12 and have debugged down to the C implementation of&lt;/DIV&gt;&lt;DIV&gt;dword&amp;nbsp;n&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;n%10&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;the code works OK but TOTALLY CLOBBERS GLOBAL variables.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;actual code&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/**This routine converts numbers of type word to a string format of 0xXXXX===============================================================================**DESCRIPTION:***This routine converts numbers of type word to a string format of 0xXXXX in *decimal notation.*CALLING SEQUENCE:&amp;nbsp;&amp;nbsp; wordToDecStr(char *s, word n)**@param *s (character pointer of size + 1&amp;nbsp; or greater).@param n&amp;nbsp; (16 bit word to be converted).@param size&amp;nbsp; (char variable indicating number of leading zeros required).*\todo- List of things to do- Remove commented code*/void wordToDecStr(unsigned char *s, dword n,char size){ unsigned char i, j; dword temp; //return in error case if((size==0)) {&amp;nbsp;&amp;nbsp; return; }&amp;nbsp;&amp;nbsp;&amp;nbsp; //fill with character zeros for (j=0;j&amp;lt;size;j++) {&amp;nbsp; s[j] = '0'; } //modulus your way from the back to the front i=0; while ((n &amp;gt; 0)&amp;amp;&amp;amp;(size&amp;gt;i))&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=(n % 10) + '0'; ////&amp;lt;&amp;lt;&amp;lt;&amp;lt;ERROR OCCURS HERE&amp;nbsp; s[size-i-1] =(char)temp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n /= 10;&amp;nbsp; i++; }//end while s[size]='\0';//string terminator}//end wordToDecStr()&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does anybody have any experience with this?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:18:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170272#M5192</guid>
      <dc:creator>Emac</dc:creator>
      <dc:date>2020-10-29T09:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Long division Modulus Errors</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170273#M5193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Where is the stack pointer SP when that code gets executed?&lt;BR /&gt;&lt;BR /&gt;The description sounds as if the application would use more stack space that which was allocated for it.&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, 05 Dec 2007 06:20:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170273#M5193</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-12-05T06:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Long division Modulus Errors</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170274#M5194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You were absolutely right, the symptoms were that the stack was clobering global variables.&amp;nbsp; I finally found the CPU build options for stack size and saw that it was originally set to 80!&amp;nbsp; I increased it and works fine now.&amp;nbsp; Thanks.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Let this be a warning to those who unit test code and find problems durring integration, stack size and subroutine nesting can bite you if you don't know what to look for.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Daniel you are awesome!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2007 23:49:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Long-division-Modulus-Errors/m-p/170274#M5194</guid>
      <dc:creator>Emac</dc:creator>
      <dc:date>2007-12-05T23:49:01Z</dc:date>
    </item>
  </channel>
</rss>

