<?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>8-bit MicrocontrollersのトピックRe: How to implement  4byte divide 2byte divide fasty?</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161505#M9808</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;If you are currently achieving the 32/16 integer division in about 200 cycles, this would seem quite fast.&amp;nbsp; Normally I would expect about 10 times this amount, even if written directly in assembly code.&amp;nbsp; It will be interesting to see what the execution time of the two code snippets turns out to be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hardware divide for the HCS08 handles only an 8-bit divisor, and this is the limiting factor in its use - a 32/8 bit division would give fast code.&amp;nbsp;&amp;nbsp;Increasing the size of the divisor to 16 bits necessarily results in a slower&amp;nbsp;software division process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To achieve substantially faster calculation would require an alternative MCU&amp;nbsp;containing hardware to support a 16-bit divisor - probably a 16-bit or 32-bit device.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Nov 2010 13:59:44 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-11-09T13:59:44Z</dc:date>
    <item>
      <title>How to implement  4byte divide 2byte divide fasty?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161502#M9805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in my application,&amp;nbsp;&amp;nbsp; 4 bytes / 2 byte is need&amp;nbsp; as following,&lt;/P&gt;&lt;P&gt;dword&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a;&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; a&amp;nbsp; is type of unsigned long&amp;nbsp;, 4 bytes &amp;nbsp;*/&lt;/P&gt;&lt;P&gt;word&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b;&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; b is type of&amp;nbsp; unsigned integer, 2 bytes&amp;nbsp; */&lt;/P&gt;&lt;P&gt;word&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;c =&amp;nbsp; a /b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I code it&amp;nbsp; in&amp;nbsp; C ,&amp;nbsp;&amp;nbsp; c =a /b take more than&amp;nbsp;200 CPU cycles, it is too long for my application, so&amp;nbsp; i consider implimenting it&amp;nbsp; in assembly&amp;nbsp; language,&amp;nbsp; my CPU is HCS08, and only have one division instruction:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIV&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;&amp;nbsp; &amp;nbsp;A&amp;lt;--(H:A) /(X);&amp;nbsp; H&amp;lt;-- remainder&amp;nbsp;6 CPU cycles&amp;nbsp;, 16-bit by 8 bit divide instructions &amp;nbsp;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to implement&amp;nbsp; a&amp;nbsp; 4 bytes&amp;nbsp; variable divide 2 bytes variable&amp;nbsp; in assembly&amp;nbsp; fastly?&amp;nbsp;&amp;nbsp; thanks .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Nov 2010 09:10:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161502#M9805</guid>
      <dc:creator>CASEYKEVIN</dc:creator>
      <dc:date>2010-11-09T09:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement  4byte divide 2byte divide fasty?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161503#M9806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here is MC68xx &amp;nbsp; uP code for 4byte /4 byte, I have used this for years.&lt;/P&gt;&lt;P&gt;You can edit it for 2 byte dividend.&lt;/P&gt;&lt;P&gt;You could probably make it faster by using stack indexing...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;*NAME:BIGDIV&lt;/DIV&gt;&lt;DIV&gt;*DESC: &amp;nbsp; &amp;nbsp; &amp;nbsp; 32BIT DIVIDE BY 32BIT&lt;/DIV&gt;&lt;DIV&gt;* @DIVBUF bytes&lt;/DIV&gt;&lt;DIV&gt;* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0...4 = DIVISOR.&lt;/DIV&gt;&lt;DIV&gt;* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5...9 = DIVIDEND&lt;/DIV&gt;&lt;DIV&gt;* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10..14 = RESULT&lt;/DIV&gt;&lt;DIV&gt;* CHECKS FOR /0 ,&amp;nbsp;CY SET IF ERROR&lt;/DIV&gt;&lt;DIV&gt;CLRDIV: &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;;call first to clear ram area&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDHX &amp;nbsp; &amp;nbsp; #DIVBUF&lt;/DIV&gt;&lt;DIV&gt;CLRDIV10&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; ,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; AIX &amp;nbsp; &amp;nbsp; &amp;nbsp;#1&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CPHX &amp;nbsp; &amp;nbsp; #(DIVBUF+14T) &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BNE &amp;nbsp; &amp;nbsp; &amp;nbsp;CLRDIV10&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; RTS&lt;/DIV&gt;&lt;DIV&gt;DIVERR&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SEC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; SET CY IF CANNOT DIVIDE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 14T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 13T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; RTS&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;BIGDIV:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDHX &amp;nbsp; &amp;nbsp; #DIVBUF &amp;nbsp; &amp;nbsp; &amp;nbsp;; &amp;nbsp; 5 BYTE DIV &amp;nbsp; POINT TO MSD&lt;/DIV&gt;&lt;DIV&gt;BIGD10:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 10T,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; RESULT MSD&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 11T,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 12T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 13T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; 14T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 8,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; CHECK IF ZERO&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ORA &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ORA &amp;nbsp; &amp;nbsp; 9,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ORA &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ORA &amp;nbsp; &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BEQ &amp;nbsp; &amp;nbsp; DIVERR&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 4,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; CHK IF DIV &amp;lt; DIVIDEND&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SUB &amp;nbsp; &amp;nbsp; 9,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 3,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; CHK IF DIV &amp;lt; DIVIDEND&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 8,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 2,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; CHK IF DIV &amp;lt; DIVIDEND&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 1,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; &amp;nbsp;CHK IF DIV &amp;lt; DIVIDEND&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 0,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BCS &amp;nbsp; &amp;nbsp; DIVERR&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLR &amp;nbsp; &amp;nbsp; SRCTMP&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; INC &amp;nbsp; &amp;nbsp; SRCTMP&lt;/DIV&gt;&lt;DIV&gt;DIV3210 &amp;nbsp;TST &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BMI &amp;nbsp; &amp;nbsp; DIV3212&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ASL &amp;nbsp; &amp;nbsp; &amp;nbsp;9,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; SHIFT UP DIVSR TO LINE UP WITH DIVDN&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 8,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; INC &amp;nbsp; &amp;nbsp; SRCTMP&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BRA &amp;nbsp; &amp;nbsp; DIV3210&lt;/DIV&gt;&lt;DIV&gt;DIVLNE &amp;nbsp;LSR &amp;nbsp; &amp;nbsp;5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROR &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROR &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROR &amp;nbsp; &amp;nbsp; 8,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROR &amp;nbsp; &amp;nbsp; 9,X&lt;/DIV&gt;&lt;DIV&gt;DIV3212 &amp;nbsp;LDA &amp;nbsp; &amp;nbsp; 4,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; &amp;nbsp;DIVDEND-DIVSR&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SUB &amp;nbsp; &amp;nbsp; 9,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 4,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 3,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 8,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 3,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 2,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 2,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 1,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 1,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 0,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SBC &amp;nbsp; &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 0,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BCS &amp;nbsp; &amp;nbsp; DIV3220 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; DIDNT FIT&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SEC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;;ADD BIT TO RESULT&lt;/DIV&gt;&lt;DIV&gt;DIV3240 &amp;nbsp;ROL &amp;nbsp; 14T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 13T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 12T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 11T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ROL &amp;nbsp; &amp;nbsp; 10T,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; DEC &amp;nbsp; &amp;nbsp; SRCTMP &amp;nbsp; &amp;nbsp; &amp;nbsp; ; ALL DONE?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BNE &amp;nbsp; &amp;nbsp; DIVLNE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; DIVIDE NEXT BIT&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; DONE OK&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; RTS&lt;/DIV&gt;&lt;DIV&gt;DIV3220&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 4,X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;RESTORE DIVEND-DIVSR&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ADD &amp;nbsp; &amp;nbsp; 9,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 4,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 3,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ADC &amp;nbsp; &amp;nbsp; 8,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 3,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 2,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ADC &amp;nbsp; &amp;nbsp; 7,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 2,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 1,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ADC &amp;nbsp; &amp;nbsp; 6,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 1,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; LDA &amp;nbsp; &amp;nbsp; 0,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ADC &amp;nbsp; &amp;nbsp; 5,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; STA &amp;nbsp; &amp;nbsp; 0,X&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; CLC&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; BRA &amp;nbsp; &amp;nbsp; DIV3240&lt;/DIV&gt;&lt;DIV&gt;*******************************&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Nov 2010 09:55:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161503#M9806</guid>
      <dc:creator>donw</dc:creator>
      <dc:date>2010-11-09T09:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement  4byte divide 2byte divide fasty?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161504#M9807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And here is an old routine of mine, originally written for the 68HC05.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is a 24bit divided by 16bit, but easily expanded to 32bit divided by 16bit. It should also be optimized for the S08.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I'm not sure either of these two routines (Don's or mine) will do better than 200 cycles.&lt;/P&gt;&lt;PRE&gt;;;;; Divide 24 by 16;; Divides a 24 bit, unsigned integer by a 16 bit unsigned integer.; Enter with the dividend in the Psuedo-Accumulator and the divisor; in the X:A register.  Exits with the 24 bit Quotient in the P.Acc.; and the 16 bit remainder in X:A.;Div24x16: STXA .MULT.  ;put the divisor someplace safe ST24 TEMP  ;move divedend to TEMP CLR24 ,,  ;zero the low 24 bits ldx #24  ;number of times through the loop;; Main Loop.; Rotate dividend into A, one bit at a time,; and check if a subtract is needed.;; shift 32 bit pseudo-accumulator around left one position.;d24_1: asl TEMP+2  ;start with byte 0 rol TEMP+1  ;into byte 1 rol TEMP  ;and into byte 2 rol ACCUM0  ;then around into byte 0 of p-acc rol ACCUM1  ;and finaly into byte 1 of p-acc; bcs d24_2  ;do a subtract if hi-bit went into carry CMP16 .MULT.  ;is it worth a subtract? bcs d24_3  ;skip if no subtract needed here;    ;leave a zero in lo-bit of quotient;; Do the subtract and put a 1 into lo-bit of quotient.;d24_2: SUB16 .MULT.  ;subtract bset 0,TEMP+2 ;set new  lowest bit in quotient;; decrement the loop count and continue if not zero;d24_3: decx   ;decrement loop counter bne d24_1  ;and loop until all bits are done;; all bits are done.  Quotient is in TEMP:TEMP+1:TEMP+2; and remainder is in ACCUM1:0.  we move them.; lda TEMP  ;get high byte of quotient sta ACCUM2  ;put it where it belongs ldx ACCUM1  ;put high byte of remainder in X lda TEMP+1  ;get mid byte of quotient sta ACCUM1  ;put it where it belongs lda ACCUM0  ;get low byte of remainder sta .MULT.  ;put aside lda TEMP+2  ;get low byte of quotient sta ACCUM0  ;put where belongs lda .MULT.  ;get last of remainder back rts   ;return with answers;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:06:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161504#M9807</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2020-10-29T09:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement  4byte divide 2byte divide fasty?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161505#M9808</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;If you are currently achieving the 32/16 integer division in about 200 cycles, this would seem quite fast.&amp;nbsp; Normally I would expect about 10 times this amount, even if written directly in assembly code.&amp;nbsp; It will be interesting to see what the execution time of the two code snippets turns out to be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hardware divide for the HCS08 handles only an 8-bit divisor, and this is the limiting factor in its use - a 32/8 bit division would give fast code.&amp;nbsp;&amp;nbsp;Increasing the size of the divisor to 16 bits necessarily results in a slower&amp;nbsp;software division process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To achieve substantially faster calculation would require an alternative MCU&amp;nbsp;containing hardware to support a 16-bit divisor - probably a 16-bit or 32-bit device.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Nov 2010 13:59:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161505#M9808</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-11-09T13:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement  4byte divide 2byte divide fasty?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161506#M9809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello CASEYKEVIN,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you won't get faster results from a 9S08 CPU, more likely much slower under certain conditions (numbers).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Look at the sources of the compiler's division routine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use a better CPU (Coldfire) or try to solve the task with a multiplication.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oliver&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Nov 2010 20:36:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-implement-4byte-divide-2byte-divide-fasty/m-p/161506#M9809</guid>
      <dc:creator>Obetz</dc:creator>
      <dc:date>2010-11-12T20:36:48Z</dc:date>
    </item>
  </channel>
</rss>

