<?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 Re: Timing to do multiplication and divide in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207051#M17501</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assuming the initial value of the variable &lt;FONT face="courier new,courier"&gt;divisor&lt;/FONT&gt; is&amp;nbsp;the unsigned 16-bit value 100602 (not entirely clear from your post), the initial value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;j&lt;/FONT&gt; is 2, and that you complete the loop three times, rather than twice, I would expect to get the result &amp;nbsp;0, 6, 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your problem is with&amp;nbsp;the line &lt;FONT face="courier new,courier"&gt;activeArray[j] = tempunit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;It would seem that the expression should be&lt;/FONT&gt; &lt;FONT face="courier new,courier"&gt;activeArray[j] = temptens;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Perhaps the code might be simplified, as follows&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;for (j = 2; j; j--) {  // Loop twice only  activeArray[j] = (byte)(divisor % 100);  divisor /= 100;      // new value to mod by 100}activeArray[0] = (byte)divisor;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Jun 2010 01:19:47 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-06-16T01:19:47Z</dc:date>
    <item>
      <title>Timing to do multiplication and divide</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207050#M17500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hardware: MS9SO8GT60 with 32.768 kHZ xtal&lt;/P&gt;&lt;P&gt;programmer: Cyclone Pro HC08 - HCS08&lt;/P&gt;&lt;P&gt;IDE: Freescale Codewarrior 5.9.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to be having a timing issue with how long it takes to perform the calculation, and then assigning the computed value.&lt;/P&gt;&lt;P&gt;I assumed it wouldnt move to the next step, before the calculation had finished, but when I step through the code, it looks like it assigns 'tempunit' to activeArray before the value is finished&amp;nbsp;calculating. and therefore, assigns '0'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so all this is doing is a 6 digit number (date) and putting it into a 3 byte array (activeArray)&lt;/P&gt;&lt;P&gt;so for example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;divisor = 10/06/02&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then activeArray should be [ 10, 6, 2 ];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it ends up being [0, 6, 2]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp; for (i=0;i&amp;lt;=2;i++){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempunit = (BYTE)(divisor%10);&amp;nbsp;&amp;nbsp;&amp;nbsp; divisor /= 10;&amp;nbsp;&amp;nbsp;&amp;nbsp; //new value to mod by 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temptens =&amp;nbsp; (BYTE)(divisor%10);&amp;nbsp;&amp;nbsp;&amp;nbsp; temptens *= 10;&amp;nbsp;&amp;nbsp;&amp;nbsp; temptens += tempunit;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeArray[j] = tempunit;&amp;nbsp;&amp;nbsp;&amp;nbsp; j--;&amp;nbsp;&amp;nbsp;&amp;nbsp; divisor /= 10;&amp;nbsp;&amp;nbsp;&amp;nbsp; //new value to mod by 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is this possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jun 2010 22:16:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207050#M17500</guid>
      <dc:creator>New_to_HC08</dc:creator>
      <dc:date>2010-06-15T22:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Timing to do multiplication and divide</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207051#M17501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assuming the initial value of the variable &lt;FONT face="courier new,courier"&gt;divisor&lt;/FONT&gt; is&amp;nbsp;the unsigned 16-bit value 100602 (not entirely clear from your post), the initial value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;j&lt;/FONT&gt; is 2, and that you complete the loop three times, rather than twice, I would expect to get the result &amp;nbsp;0, 6, 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your problem is with&amp;nbsp;the line &lt;FONT face="courier new,courier"&gt;activeArray[j] = tempunit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;It would seem that the expression should be&lt;/FONT&gt; &lt;FONT face="courier new,courier"&gt;activeArray[j] = temptens;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Perhaps the code might be simplified, as follows&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;for (j = 2; j; j--) {  // Loop twice only  activeArray[j] = (byte)(divisor % 100);  divisor /= 100;      // new value to mod by 100}activeArray[0] = (byte)divisor;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jun 2010 01:19:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207051#M17501</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-06-16T01:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Timing to do multiplication and divide</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207052#M17502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow. I am a retard.&lt;BR /&gt;I ended up just coding a new loop anyway, coz I often find, when I cant see the bug, it helps to start from scratch...is it just me that has this problem?&lt;BR /&gt;it is very similar to your solution&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;   for (i=0;i&amp;lt;=2;i++){     activeArray[j] =  (BYTE)(divisor%100);      divisor /= 100;      if (j&amp;gt;0) j--;         }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks anyway!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jun 2010 18:39:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Timing-to-do-multiplication-and-divide/m-p/207052#M17502</guid>
      <dc:creator>New_to_HC08</dc:creator>
      <dc:date>2010-06-17T18:39:11Z</dc:date>
    </item>
  </channel>
</rss>

