TensThousands equ 0x20
Thousands equ 0x21
Hundreds equ 0x22
Tens equ 0x23
units equ 0x24
working equ 0x25
numtoconLb equ 0x26
numtoconHb equ 0x27
count equ 0x28
Start
clrf tensthousands
clrf Thousands
clrf Hundreds
clrf Tens
clrf Units
;this is the number to be converted
movlw 0xDD
movwf numtoconHB
movlw 0xF5
movwf numtoconLB
movlw d'3'
movwf count
InitialShift
;perform 3 shifts before 1st test
rlf numtoconLB
rlf numtoconHB
rlf Units
decfsz count
goto InitialShift
movlw d'13'
movwf count
ShiftLoop
movfw Units
andlw b'1111'
movwf working
movlw d'5'
subwf working,0
SKPC
Goto TestUnitsUpperNibbleByte
movlw d'3'
addwf units
TestUnitsUpperNibbleByte
movfw units
andlw b'11110000'
movwf working
movlw H'50'
subwf working,0
SKPC
goto TestHundredsbyteLowerNibble
movlw H'30'
addwf units
TestHundredsbyteLowerNibble
movfw Hundreds
andlw b'1111'
movwf working
movlw d'5'
subwf working,0
SKPC
Goto TestHundredsbyteUpperNibble
movlw d'3'
addwf Hundreds
TestHundredsbyteUpperNibble
movfw Hundreds
andlw b'11110000'
movwf working
movlw H'50'
subwf working,0
SKPC
goto TestTensThousandsByteLowerNibble
movlw H'30'
addwf Hundreds
;Use tensthousands, means that we need not move after conversion
TestTensThousandsByteLowerNibble
movfw TensThousands
andlw b'1111'
movwf working
movlw d'5'
subwf working,0
SKPC
Goto Shiftbits
movlw d'3'
addwf TensThousands
shiftbits
;rotate through the C flag and into the variables
rlf numtoconLB
rlf numtoconHB
rlf Units
rlf Hundreds
rlf TensThousands
decfsz count
goto ShiftLoop
;get the BDC results in the correct variables
movfw Units
Movwf Tens
swapf Tens,1
movlw b'1111'
andwf Units,1
andwf Tens,1
movfw Hundreds
Movwf Thousands
swapf Thousands,1
movlw b'1111'
andwf Hundreds,1
andwf Thousands,1
;Convert variables to their ASCII code
movlw d'48'
addwf TensThousands
addwf Thousands
addwf Hundreds
addwf Tens
addwf Units