## Binary to ASCII, 8 bit to 3 digits

from Daniel Serpell

```; ========================================================
bin2ascii
; Input:  reg. W
; Output: d2 / d1 / d0 (assumed in the same bank)
; Assumed "banksel d0"
; Used 40 instructions / 30-39 cycles (counting CALL/RETURN)
; average 34.77 cycles (from 0..255).

clrf d2
clrf d1

; Test if W is more than 199 (200 to 255)
btfss STATUS,C
goto  digit100
bsf   d2,1
; Here we are in the 200 - 255 range, so it is possible to
; skip the .100 and .80 parts
goto  digit40

; Now, we have a number from -200 to -1 (0..199),
; we add 100 to detect -100 to -1 (100..199).
digit100
btfss STATUS,C
goto  \$+3
bsf   d2,0

; Now, we have a number from -100 to -1 (0..99),
; we add 20 to detect -20 to -1 (80..99).
btfss STATUS,C
goto  digit40
bsf   d1,3
; We skip the 4 and 2, as the largest value is 8 + 1 = 9.
goto digit10

; Now, we have a number from -80 to -1 (0..79),
; we add 40 to detect -40 to -1 (40..79).
digit40
btfss STATUS,C
goto  \$+3
bsf   d1,2

; Now, we have a number from -40 to -1 (0..39),
; we add 20 to detect -20 to -1 (20..39).
btfss STATUS,C
goto  \$+3
bsf   d1,1

; Now, we have a number from -20 to -1 (0..19),
; we add 10 to detect -10 to -1 (10..19).
digit10
btfss STATUS,C
goto  \$+3
bsf   d1,0

; Now, we have a number from -10 to -1 (0..9),
; we add 58 to bring it from 48 to 57 (0..9).
movwf d0

movlw 0x30
xorwf d1,f
xorwf d2,f

return

```
```
```

Archive:

 file: /Techref/microchip/math/radix/b2a-8b3d-ds.htm, 2KB, , updated: 2009/2/6 18:46, local time: 2018/12/9 21:29, TOP NEW HELP FIND:  54.84.236.168:LOG IN

 ©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! /  PIC Microcontoller Radix Math Method

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 2018 contributors: o List host: MIT, Site host massmind.org, Top posters @20181209 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Neil, Isaac M. Bavaresco, Bob Blick, Harold Hallikainen, AB Pearce - UKRI STFC, John Gardner, * 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.

.