ON 20080115@10:34:13 AM at page: http://techref.massmind.org/techref/microchip/math/radix/a2b-3d8b-rw.htm#39461.3707638889 James Newton[JMN-EFP-786] removed post 39461.3707638889 |Delete '

Hang on I'll try that again

; This how I'd have done it as it saves having any loops - 18 clks

; ASCII DIGIT1=(hundreds), DIGIT2=(tens), DIGIT3=(units). The hex value is in OUT.

; The routine does not affect any of the ASCII DIGIT values, or need addition registers.

; CAUTION: The routine does not test that the ASCII values are valid !

; I have just written this code to show the idea, it hasn't been tested in anyway.

CONV_ASCII_HEX

movlw 0X0F ; Bit pattern to strip off ASCII offset

andwf DIGIT3, W ; convert ASCII value to a number (units)

movwf OUT, F ; start the running total (units)

rlf DIGIT2, W ; read 2*DIGIT2 doing (tens)

andlw 0x1E ; clear ASCII offset + odd bits

addwf OUT, F ; add to running total total 2T + U

addwf OUT, F ; add to running total total 4T + U

addwf OUT, F ; add to running total total 6T + U

addwf OUT, F ; add to running total total 8T + U

addwf OUT, F ; add to running total total 10T + U

movlw '1' ; (Hundred) digit can only usefully be 1 or 2

subwf DIGIT1, W ; test value of DIGIT1 (sets flags)

movlw 0x00 ; clear value to add to total

btfsc STATUS, C ; test if result negative ie DIGIT1 was <='0'

movlw 200 ; DIGIT1 was >'0', total needs inc by 100 or 200

btfsc STATUS, Z ; test if result = '1'

movlw 100 ; DIGIT1 was = '1' inc total by 100

addwf OUT, F ; add 0, 100 or 200 to total as req

  • ' ON 20080115@10:34:48 AM at page: http://techref.massmind.org/techref/microchip/math/radix/a2b-3d8b-rw.htm# James Newton[JMN-EFP-786] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\radix\a2b-3d8b-rw.htm&version=6