<?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: Fast 16 bit binary to 5 digit BCD for S08 in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302389#M20643</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's may not technically be necessary but certainly a very good idea. Doing so will shorten the ground paths, reducing noise. Plus I expect it'll allow you to sink more current.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At least that's my software-engineering take on things.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Mar 2014 18:10:31 GMT</pubDate>
    <dc:creator>implicit</dc:creator>
    <dc:date>2014-03-31T18:10:31Z</dc:date>
    <item>
      <title>Fast 16 bit binary to 5 digit BCD for S08</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302386#M20640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am looking for a fast 16 bit&amp;nbsp; binary to a 5 BCD digit routine in assembler for an S08. Can anyone make any suggestions?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ascii&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 11:00:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302386#M20640</guid>
      <dc:creator>asciidv</dc:creator>
      <dc:date>2014-03-24T11:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Fast 16 bit binary to 5 digit BCD for S08</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302387#M20641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How fast is fast?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This really boils down to dividing the binary number by ten four times and saving the remainders as the BCD digits, something which is straightforward on the HCS08 given the fast division instruction. The only "trick" is that the two of divisions by ten may overflow (e.g. the 16/8-bit division may generate larger than 8-bit results) and therefore need to be synthesized through pairs of divisions where the remainder from the MSB carries into the LSB division. Some contortions are needed to get the right values into the proper places, but that's just how optimized code goes on the terminally register-starved S08.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following is my half-baked attempt which takes the 16-bit &lt;EM&gt;bin&lt;/EM&gt; variable as input and spits out a 3-byte (big-endian) &lt;EM&gt;bcd&lt;/EM&gt; buffer as output. It should take 103 cycles assuming zero-page variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;lda&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bin+0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;1st division (0..65535 / 10)
ldhx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #10
div
psha
lda&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bin+1
div
sta&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+1
pula
pshh
ldhx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;2nd division (0..6553 / 10)
div
psha
lda&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+1
div
sthx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+1
pulh&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; ;3rd division (0..655 / 10)
div
pshh
ldhx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;4th division (0..65 / 10)
div
pshh

sta&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+0&amp;nbsp;&amp;nbsp;&amp;nbsp; ;Save and pack and the final BCD nibbles
tsx
lda&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+1
nsa
ora&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2,x
sta&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+2
pula
nsa
ora&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1,x
sta&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bcd+1
ais&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #2&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 17:18:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302387#M20641</guid>
      <dc:creator>implicit</dc:creator>
      <dc:date>2014-03-31T17:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Fast 16 bit binary to 5 digit BCD for S08</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302388#M20642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Johan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for this. 103 cycles is fast enough (at the moment!). Since you must be familiar with the S08 could I trouble you and ask you another question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a PCB layout for the S08 (we use the 64 pin S08) do you think it is necessary to connect all the external Vss pins. I know that it might be best practice to do so, but in the real world do you think it is necessary?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ascii&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 17:31:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302388#M20642</guid>
      <dc:creator>asciidv</dc:creator>
      <dc:date>2014-03-31T17:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Fast 16 bit binary to 5 digit BCD for S08</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302389#M20643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's may not technically be necessary but certainly a very good idea. Doing so will shorten the ground paths, reducing noise. Plus I expect it'll allow you to sink more current.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At least that's my software-engineering take on things.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 18:10:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Fast-16-bit-binary-to-5-digit-BCD-for-S08/m-p/302389#M20643</guid>
      <dc:creator>implicit</dc:creator>
      <dc:date>2014-03-31T18:10:31Z</dc:date>
    </item>
  </channel>
</rss>

