<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Pouzivam tohle:</p>
    <p>Treba to pomuze, ale je to upraveny pro NXP ARM MCU jenz neumi
      delit integery, ale maji HW delicku.<br>
    </p>
    <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
      <div
style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre;"><p
      style="margin:0;"><span style="color:#7f0055;font-weight:bold;">void</span><span
      style="color:#000000;"> </span><span
      style="color:#000000;font-weight:bold;">UARTLog_t::</span><span
      style="color:#000000;background-color:#d4d4d4;font-weight:bold;">itoa</span><span
      style="color:#000000;">(</span><span
      style="color:#7f0055;font-weight:bold;">int</span><span
      style="color:#000000;"> val){</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span style="color:#3f7f5f;">// original source <a class="moz-txt-link-freetext" href="https://github.com/wsq003/itoa_for_linux/blob/master/itoa.c">https://github.com/wsq003/itoa_for_linux/blob/master/itoa.c</a></span></p><p
      style="margin:0;"><span style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">const</span><span
      style="color:#000000;"> </span><span
      style="color:#7f0055;font-weight:bold;">unsigned</span><span
      style="color:#000000;"> </span><span
      style="color:#7f0055;font-weight:bold;">int</span><span
      style="color:#000000;"> radix = 10;</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">char</span><span
      style="color:#000000;">* p = </span><span style="color:#0000c0;">msg</span><span
      style="color:#000000;">;</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">unsigned</span><span
      style="color:#000000;"> </span><span
      style="color:#7f0055;font-weight:bold;">int</span><span
      style="color:#000000;"> a;        </span><span
      style="color:#3f7f5f;">//every digit</span></p><p
      style="margin:0;"><span style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">char</span><span
      style="color:#000000;">* b;              </span><span
      style="color:#3f7f5f;">//start of the digit char</span></p><p
      style="margin:0;"><span style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">char</span><span
      style="color:#000000;"> temp;</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">unsigned</span><span
      style="color:#000000;"> </span><span
      style="color:#7f0055;font-weight:bold;">int</span><span
      style="color:#000000;"> u;</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#7f0055;font-weight:bold;">if</span><span
      style="color:#000000;"> (val < 0)</span></p><p
      style="margin:0;"><span style="color:#000000;">      {</span></p><p
      style="margin:0;"><span style="color:#000000;">              *p++ = </span><span
      style="color:#2a00ff;">'-'</span><span style="color:#000000;">;</span></p><p
      style="margin:0;"><span style="color:#000000;">              val = 0 - val;</span></p><p
      style="margin:0;"><span style="color:#000000;">      }</span></p><p
      style="margin:0;"><span style="color:#000000;">      u = (</span><span
      style="color:#7f0055;font-weight:bold;">unsigned</span><span
      style="color:#000000;"> </span><span
      style="color:#7f0055;font-weight:bold;">int</span><span
      style="color:#000000;">)val;</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    b = p;</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#7f0055;font-weight:bold;">do</span></p><p
      style="margin:0;"><span style="color:#000000;">      {</span></p><p
      style="margin:0;"><span style="color:#000000;">              </span><span
      style="color:#3f7f5f;">/* Original code</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#3f7f5f;">            a = u % radix;</span></p><p
      style="margin:0;"><span style="color:#3f7f5f;">              u /= radix;</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#3f7f5f;">            */</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">            </span><span
      style="color:#3f7f5f;">// HW division</span></p><p
      style="margin:0;"><span style="color:#000000;">              a = MMDVSQ_GetDivideRemainder(MMDVSQ0, u, radix, </span><span
      style="color:#7f0055;font-weight:bold;">true</span><span
      style="color:#000000;">);</span></p><p style="margin:0;"><span
      style="color:#000000;">              u = MMDVSQ_GetDivideQuotient(MMDVSQ0, u, radix, </span><span
      style="color:#7f0055;font-weight:bold;">true</span><span
      style="color:#000000;">);</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">            *p++ = a + </span><span
      style="color:#2a00ff;">'0'</span><span style="color:#000000;">;</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    } </span><span
      style="color:#7f0055;font-weight:bold;">while</span><span
      style="color:#000000;"> (u > 0);</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    *p-- = 0;</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#3f7f5f;">//swap</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#7f0055;font-weight:bold;">do</span><span
      style="color:#000000;"> {</span></p><p style="margin:0;"><span
      style="color:#000000;">              temp = *p;</span></p><p style="margin:0;"><span
      style="color:#000000;">              *p = *b;</span></p><p style="margin:0;"><span
      style="color:#000000;">              *b = temp;</span></p><p style="margin:0;"><span
      style="color:#000000;">              --p;</span></p><p style="margin:0;"><span
      style="color:#000000;">              ++b;</span></p><p style="margin:0;"><span
      style="color:#000000;">      } </span><span
      style="color:#7f0055;font-weight:bold;">while</span><span
      style="color:#000000;"> (b < p);</span></p><p style="margin:0;"><span
      style="color:#000000;">      SendMsg();</span></p><p style="margin:0;"><span
      style="color:#000000;">}</span></p><p style="margin:0;"><span
      style="color:#000000;">
</span></p><p style="margin:0;"><span style="color:#000000;">Slavek
</span></p></div>
    </div>
    <p></p>
    <pre class="moz-signature" cols="72">Ing. Slavomir Skopalik
Executive Head
Elekt Labs s.r.o.
MASA - Collection and evaluation of data from machines and laboratories
<a class="moz-txt-link-freetext" href="http://eng.elektlabs.com/products-and-services/masa">http://eng.elektlabs.com/products-and-services/masa</a>
-----------------------------------------------------------------
Address:
Elekt Labs s.r.o.
Chaloupky 158
783 72 Velky Tynec
Czech Republic
---------------------------------------------------------------
Mobile: +420 724 207 851
<a class="moz-txt-link-freetext" href="skype:skopaliks">skype:skopaliks</a>
<a class="moz-txt-link-abbreviated" href="mailto:e-mail:skopalik@elektlabs.com">e-mail:skopalik@elektlabs.com</a>
<a class="moz-txt-link-freetext" href="http://www.elektlabs.com">http://www.elektlabs.com</a></pre>
    <div class="moz-cite-prefix">On 15.04.24 21:33, Miroslav Mraz wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:0ee24e3c-8272-483f-aced-f4ec66d2c764@volny.cz">No je to
      vyzobnuté z nějaké knihovny, sám bych se s tou rekurzí babral celý
      den a není to nijak optimalizované pro 8-bit. Samozřejmě, pokud
      není rekurze vysloveně "na ocase", tak to žere zásobník (jinak si
      to překladač dokáže převést na cyklus), ale pokud v něm je už
      nějaké to místo, tak to zas tolik nevadí. Jenže bez té rekurze to
      neuděláte tak jednoduše, protože ty číslice přibývají odzadu.
      <br>
      I když by šlo plnit bufer obráceně (od konce) a nakonec vyplivnout
      ukazatel na poslední zapsaný znak - tedy vlastně první. Ale je to
      takové divné.
      <br>
      <br>
      Mrazík
      <br>
      <br>
      On 15. 04. 24 19:48, Jan Waclawek wrote:
      <br>
      <blockquote type="cite">Mozno to je jednoduche, ale rekurzia v mcu
        - najma 8-bitovom - je dost
        <br>
        silne nie, kym sa pracne nedokaze ze ano.
        <br>
        <br>
        Rule of the thumb je, ze 1 bit RAM je 6 tranzistorov kym 1 bit
        FLASH je 1
        <br>
        tranzistor (ano ja viem ze to je porovnanie jablk s hruskami,
        ale nejake
        <br>
        cislo treba povedat a toto odovodnenie znie mudro) takze asi
        podobna je aj
        <br>
        hodnota RAM voci FLASH.
        <br>
        <br>
        Je tam dost parametrov aj lokalnych premennych, vsetky int-ovite
        co je u
        <br>
        AVR 16-bit, takze by som povedal tak od oka ze 12 byte na
        iteraciu; mozno
        <br>
        nieco z toho moze byt 8-bit? Takze pre 5 cislic to je 60 byte,
        dobre som
        <br>
        ratal? Cize moj rule of the thumb hovori, ze len tato spotreba
        je
        <br>
        ekvivalentna asi 360B FLASH, takze to treba priratat na vrch.
        <br>
        <br>
        Ano, ano ja viem ze aj ine riesenia budu mat spotrebu RAM.
        Nevravel som
        <br>
        rule of the thumb a ze to treba pracne dokazovat?
        <br>
        <br>
        wek
        <br>
        <br>
      </blockquote>
      _______________________________________________
      <br>
      HW-list mailing list  -  sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz">www.HW.cz</a>
      <br>
      <a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a>
      <br>
      <a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a>
      <br>
    </blockquote>
  </body>
</html>