base:more_hexadecimal_to_decimal_conversion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
base:more_hexadecimal_to_decimal_conversion [2017-03-18 09:14] – BinBcd for values up to 99 verz | base:more_hexadecimal_to_decimal_conversion [2019-08-16 01:44] (current) – verz | ||
---|---|---|---|
Line 136: | Line 136: | ||
BIN .DW | BIN .DW | ||
BCD .DS | BCD .DS | ||
+ | </ | ||
+ | |||
+ | This is the same routine, just unrolled. It gains 250 cycles for that (30%). | ||
+ | Using zero page variables the gain is of 116 cycles more. | ||
+ | < | ||
+ | ; | ||
+ | ; Converts a 16bit number in BCD | ||
+ | ; | ||
+ | ; | ||
+ | ; call it with the value in bin | ||
+ | ; | ||
+ | BINBCD16 | ||
+ | SED ; Switch to decimal mode 2 | ||
+ | LDA #0 ; Ensure the result is clear 2 | ||
+ | STA bcd+0; | ||
+ | STA bcd+1; | ||
+ | STA bcd+2; | ||
+ | |||
+ | LDX #6; | ||
+ | CNVBIT1 | ||
+ | ASL bin+0 ; Shift out one bit 6 | ||
+ | ROL bin+1 ; | ||
+ | ; LDA bcd+0 ; And add into result | ||
+ | ADC bcd+0 ; | ||
+ | STA bcd+0 ; | ||
+ | ; LDA bcd+1 ; propagating any carry | ||
+ | ; ADC bcd+1 | ||
+ | ; STA bcd+1 | ||
+ | ; LDA bcd+2 ; ... thru whole result | ||
+ | ; ADC bcd+2 | ||
+ | ; STA bcd+2 | ||
+ | DEX ; And repeat for next bit 2 | ||
+ | BNE CNVBIT1 | ||
+ | |||
+ | LDX #7; | ||
+ | CNVBIT2 | ||
+ | ASL bin+0 ; Shift out one bit 6 | ||
+ | ROL bin+1 ; | ||
+ | LDA bcd+0 ; And add into result | ||
+ | ADC bcd+0 ; | ||
+ | STA bcd+0 ; | ||
+ | LDA bcd+1 ; propagating any carry 4 | ||
+ | ADC bcd+1 ; | ||
+ | STA bcd+1 ; | ||
+ | ; LDA bcd+2 ; ... thru whole result | ||
+ | ; ADC bcd+2 | ||
+ | ; STA bcd+2 | ||
+ | DEX ; And repeat for next bit 2 | ||
+ | BNE CNVBIT2 | ||
+ | |||
+ | LDX #3; | ||
+ | CNVBIT3 | ||
+ | ASL bin+0 ; Shift out one bit 6 | ||
+ | ROL bin+1 ; | ||
+ | LDA bcd+0 ; And add into result | ||
+ | ADC bcd+0 ; | ||
+ | STA bcd+0 ; | ||
+ | LDA bcd+1 ; propagating any carry 4 | ||
+ | ADC bcd+1 ; | ||
+ | STA bcd+1 ; | ||
+ | LDA bcd+2 ; ... thru whole result | ||
+ | ADC bcd+2 ; | ||
+ | STA bcd+2 ; | ||
+ | DEX ; And repeat for next bit 2 | ||
+ | BNE CNVBIT3 | ||
+ | |||
+ | CLD ; Back to binary | ||
+ | |||
+ | rts ; All Done. | ||
</ | </ |
base/more_hexadecimal_to_decimal_conversion.1489824848.txt.gz · Last modified: 2017-03-18 09:14 by verz