please dont rip this site

Atmel AVR Microcontroller Radix Conversions

16bit to ASCII Decimal via output routine by

; Universal decimal string conversion (8/16 bit unsigned)
; Register Variables:
;  Call:   var1:0  = 16 bit value to be converted
;          len     = String length
;          tmp1:0  = <Don't care> (high register must be assigned)
;          tmp2    = <Don't care>
;  Result: var1:0  = <Unknown>
;          len     = <Not changed>
;          tmp1:0  = <Unknown>
;          tmp2    = 0
; Size:  30 words
; Clock: depends on output routine
; Stack: 10 bytes max (+output routine)
; Examples:   var1    len    output
;              100      0    "100"
;             1234      0    "1234"
;                0      7    "      0"
;              100      5    "  100"
;              100      2    "100"

mk_decu8:       clr     var1            ;8 bit entry
mk_decu16:                              ;16 bit entry
                clr     tmp2            ;digit counter
                inc     tmp2            ;---- decimal string generating loop
                clr     tmp0            ;var1 /= 10;
                ldi     tmp1,16         ;
                lsl     var0            ;
                rol     var1            ;
                rol     tmp0            ;
                cpi     tmp0,10         ;
                brcs    PC+3            ;
                subi    tmp0,10         ;
                inc     var0            ;
                dec     tmp1            ;
                brne    PC-8            ;/
                subi    tmp0,-'0'       ;Push the remander (a decimal digit)
                push    tmp0            ;/
                cp      var0,tmp1       ;if(var =! 0)
                cpc     var1,tmp1       ; continue digit loop;
                brne    PC-16           ;/
                cp      tmp2,len        ;Adjust string length (this can be removed for auto-length)
                brcc    PC+5            ;
                inc     tmp2            ;
                ldi     var0,' '        ;
                push    var0            ;
                rjmp    PC-5            ;/
                pop     var0            ;Put decimal string
                 rcall  xmit            ;<-- Put a char (var0) to memory, console or any display device
                dec     tmp2            ;
                brne    PC-3            ;/

See also:

file: /Techref/atmel/avr/bin2ascii16b-ec.htm, 2KB, , updated: 2007/9/14 18:32, local time: 2018/3/21 23:21,

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF=""> Atmel AVR, atmega, Microcontroller, embedded controller, radix conversion, 16bit to ASCII Decimal</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2018 contributors:
o List host: MIT, Site host, Top posters @20180321 RussellMc, Isaac M. Bavaresco, Sean Breheny, Van Horn, David, Neil, alan.b.pearce, Bob Blick, David C Brown, John Gardner, Brent Brown,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!