please dont rip this site

PIC Microcontoller Radix Math Method

Binary to ASCII, 16 bit to 5 digits (1 at a time) no temp register (!)

; by Rich Leggitt with tweaks by Scott Dattalo and bugfix by Dmitry Kiryashov and Nikolai Golovchenko
; given 16 bit data in HI and LO, extract decimal digits
; requires one Output register called temp, HI and LO are destroyed.
; 42 instructions and less than 269 (or 252 with known_zero) instructions executed
        clrf temp
        goto $+2                ;[NG] was: skip
sub10k  incf temp,f
        movlw 10000 & 255
        subwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
IFNDEF known_zero
        movlw 10000 >> 8
        skpc
        movlw (10000>>8)+1      ;[NG] was: addlw 1     ; this sucks
        subwf HI,f
ELSE
	rlf     known_zero,W
	sublw   (10000>>8)+1	;bugfix by Dmitry Kiryashov and Nikolai Golovchenko
	subwf   Hi,F
ENDIF
        bc sub10k               ;9*7=63/8*7=56 inst in loop for 60900 (worst)
        output(temp);

        movlw 10
        movwf temp
add1K   decf temp,f
        movlw 1000 & 255
        addwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
IFNDEF known_zero
        movlw 1000 >> 8
        skpnc
        movlw (1000>>8)+1       ;[NG] was: addlw 1
        addwf HI,f
ELSE
	rlf   known_zero,w
	addlw 1000 >> 8
	addwf HI,f
ENDIF
        bnc add1k               ;9*10=90/8*10=80 inst in loop for 60900
        output(temp);

;Scott takes over here
	clrf  temp
	movlw 100
	goto $+2                ;[NG] was: skip
sub100
	incf  temp,f
	subwf LO,f
	skpnc                   ;[NG] was: skpc
	goto sub100

	decf  HI,f
	btfss HI,7	;Check msb instead of carry for underflow.
	goto sub100	;4 inst per loop to 200 then 7 per loop to 900. 
			;Total 64(?) in loop for worst case

;at this point, HI = 0xff, and  0 <= LO <= 99

        output(temp)

        movlw 10
        movwf temp
add10   decf temp,f
        addwf LO,f
        bnc add10               ;40 inst in loop for worst case.
        output(temp);
        output(LO);
        return


See also:


file: /Techref/microchip/math/radix/b2a-16b5a-rl.htm, 3KB, , updated: 2002/10/31 15:57, local time: 2017/11/24 08:59,
TOP NEW HELP FIND: 
23.20.129.162:LOG IN

 ©2017 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="http://www.piclist.com/techref/microchip/math/radix/b2a-16b5a-rl.htm"> PIC Microcontoller Radix Math Method </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 2017 contributors:
o List host: MIT, Site host massmind.org, Top posters @20171124 RussellMc, Van Horn, David, James Cameron, Sean Breheny, alan.b.pearce, IVP, Neil, David C Brown, Bob Blick, Denny Esterline,
* 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 www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .