Also:

Archive:

• Thank's a lot for such an useful site ! I got several routines there and all of them work perfectly well, saving hours of brain storming for me with probably not such so good results... Denis, from France+
• You are VERY welcome! Please do consider shareing any code you do end up writing

Questions:

• brianszczepanikSPAM at @spam@yahoo.ca asks: " im looking for a way to convert an eight digit decimal number to two 16 bit words using only 16 bit architecture" +
• szarolettaSPAM at @spam@hotmail.com asks: " I am looking for relocatable code, or a macro which converts a hex number like FE8A into the corresponding ASCII-Code."

Convert the Hex digits to binary (16bits) and then convert the binary to ASCII.

Apply one of the "2 digit Hex to Binary 8 bits" routines to the first two hex digits and then again to the second, thereby producing two 8 bit values that are then passed to any one of the "16bit to ASCII Decimal 5 digits" routines. +

Interested:

See:

• shares this code:
```;some code snippets that someone might find useful...

;This routine will return the number of decimal
;hundreds from an 8-bit binary
;Input: w
;Output: w
;RAM:2
;Cycles: 12-24

GETHNDS		movwf	t1
clrf    w2
gethnds_loop	movlw	.100
incf	w2,f
subwf	t1,f
btfsc	STATUS,C
goto 	gethnds_loop
decf	w2,w
return
;---
;This routine will return the number of decimal
;tens from an 8-bit binary
;Loop based, so it might take some time...
;It needs getones too
GETTENS		movwf	t1
clrf    w2
gettens_loop	movlw	.10
incf	w2,f
subwf	t1,f
btfsc	STATUS,C
goto 	gettens_loop
decf	w2,w
goto	getones

;---
;This routine will return the number of decimal
;ones from an 8-bit binary
GETONES		movwf	w2
movlw	.10
deltens_loop	subwf	w2,f
btfsc	STATUS,C
goto 	deltens_loop
return

```
+
+

Code:

• ```Compact and fast 10bit to BCD conversion for converting

;****************************************************
;*	10bit BINARY to BCD		*
;****************************************************
;
;An implimentation of the 'Shift and add-3' Algorithm
;		for small MicroChip 'PIC' microcomputers
;
;ALGORITHM
;
;1)Shift binary number one bit left (into a BCD 'result'
;  (initially empty)
;2)If any 4 bit BCD column is greater than 5[hex] add 3[hex]
;3)Goto 1) {until the LSB binary bit is shifted out}
;
;<------MSB				LSB-----&gt;
;------------- BCD ------------]  [------ binary -----
;
;	   TENS		  UNITS
;	BCD column	BCD column	MSB	bit	bit
;	0  0  0  0	0  0  0  0	 1	 0	 1
;
;				<------	/  <---/    <---/
;Inalisation
;**************

Processor 16F818
include <p16f818.inc>

cblock	0x020	;Define variable block starting at \$020

binH		;bin is the 8bit binary value to be converted
bin		;The 2bit binary MSB's to be converted
bcdH		;Thousands (always blank)/ Hundreds nybbles
bcdL		;Tens / Units nybbles
counter
temp

endc

_bin2bcd	  movlw    	d'8'

movwf   counter

clrf    bcdL
clrf    bcdH

;Save time by not shifting in first 6 bits  (always '0's)
;--------------------------------------------------------
swapf	binH,1	;Chop off first nybble (TEN THOUSANDS)
rlf	binH,1	;Shift out first 2 MSB's(always '0's)
rlf	binH,1

;Ssave more ime by no test and add +3' for first TWO shifts
;---------------------------------------------------------------------

rlf    binH,F	;Shifting 'binH' left through carry into BCD nybbles
rlf    bcdL,F
rlf    binH,F

;Iteration loop shifts the 4 'columns' (10TH, THO, HUN, TEN, UNT) 1 bit left
;Tests each coulmn (4bit nybble) if > 5, adds '3'
;Shifts in the next MSB of the binary for conversion on the right.
;(for remaining EIGHT shifts)

Next_bit movfw   bcdL
movwf   temp
movfw   bcdL
btfsc   temp,3  ;Test MSB of Units+3 nybble in 'temp
addlw   0x03	  ;Add 3 to U nybble if units+3 MSB = 1
btfsc   temp,7  ;Test MSB of Tens+3nybble in 'temp'
movwf   bcdL

movfw	 bcdH
mmovfw	 bcdH
btfsc   temp,3  ;Test MSB of Hundreds+3 nybble in temp
btfsc   temp,7  ;Test MSB of Thousand+3 nybble in temp
movwf	 bcdH

rlf     bin,F	 ;Shift in next MSB from bin into T/UNITS
rlf	 bcdL,F  ;Shift next MSB from TENS/UNITS to TH/H
rlf     bcdH,F  ;Shift up

decfsz  counter,F
goto    Next_bit
return

end
```
+

 file: /Techref/microchip/math/radix/index.htm, 17KB, , updated: 2019/8/26 09:43, local time: 2020/6/3 15:01, TOP NEW HELP FIND:  18.206.187.81:LOG IN

 ©2020 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! PIC Microcontoller Radix Math Methods

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.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2020 contributors: o List host: MIT, Site host massmind.org, Top posters @20200603 RussellMc, Bob Blick, Jason White, Neil, David C Brown, James Cameron, Sean Breheny, madscientistatlarge, Allen Mulvey, Harold Hallikainen, * 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.

.