Hello again Truk,
I did manage to find a reference to a serial conversion method, and was able to derive the following assembly code -
***************************************************************
* 24-BIT BINARY TO BCD CONVERSION
* On entry, 3-byte register VAL contains the value to be
* converted.
* On exit, 4-byte register RESULT contains the BCD value,
* packed 2-digits per byte.
***************************************************************
BCD_CONV:LDX #24 ; Bit count
CLR RESULT+3
CLR RESULT+2
CLR RESULT+1
CLR RESULT
BC1: LDA RESULT+3
JSR BCD_ADJ ; Adjust for BCD conversion
STA RESULT+3
LDA RESULT+2
JSR BCD_ADJ ; Adjust for BCD conversion
STA RESULT+2
LDA RESULT+1
JSR BCD_ADJ ; Adjust for BCD conversion
STA RESULT+1
LDA RESULT
JSR BCD_ADJ ; Adjust for BCD conversion
STA RESULT
LSL VAL+2
ROL VAL+1
ROL VAL
ROL RESULT+3
ROL RESULT+2
ROL RESULT+1
ROL RESULT
DBNZX BC1 ; Loop for next bit
RTS
***************************************************************
* ADJUST FOR BCD CONVERSION
* On entry, ACC = byte value to be adjusted
* On exit, ACC = adjusted value (2 BCD digits)
***************************************************************
BCD_ADJ: TSTA
BEQ BA1 ; Exit if zero
PSHA
; Process lower nybble
AND #$0F
CMP #5
BLO *+4 ; Skip next if <5
ADD #3
PSHA
; Process upper nybble
LDA 2,SP ; Initial byte value
NSA
AND #$0F
CMP #5
BLO *+4 ; Skip next if <5
ADD #3
NSA
ORA 1,SP ; Combine nybbles
AIS #2 ; Adjust stack pointer
BA1: RTS
The number of bus cycles does depend, to some extent, on the value to be converted. The maximum value seems to be approximately 4500 cycles (563 us) based on preliminary tests using full chip simulation, which is marginally greater than your maximum limit.
Regards,
Mac
Message Edited by bigmac on 2006-11-0107:12 AM