base:more_hexadecimal_to_decimal_conversion
Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
base:more_hexadecimal_to_decimal_conversion [2015-04-17 04:33] – external edit 127.0.0.1 | base:more_hexadecimal_to_decimal_conversion [2017-03-18 09:14] – BinBcd for values up to 99 verz | ||
---|---|---|---|
Line 58: | Line 58: | ||
BCD .DS | BCD .DS | ||
</ | </ | ||
+ | |||
+ | Here a stripped down version to compute a BCD number not larger than 99 (single byte). You send and receive the value in A. The intermediate variables are in page zero. | ||
+ | < | ||
+ | ; Convert a 7 bit binary value to BCD | ||
+ | ; | ||
+ | ; This routine converts a binary value to BCD; the value cannot be larger than 99. | ||
+ | ; Same working principle of the other routines. | ||
+ | ; The value to convert is sent in A, and the result will be in A. X value is destroyed. | ||
+ | ; The routine executes in 124 cycles (+rts). | ||
+ | ; | ||
+ | ; Verz!!! 18-Mar-2017 | ||
+ | |||
+ | BinBcd_sb ldx #$7 ; The number of source bits 2c | ||
+ | asl ; 2c | ||
+ | ; ldx #$6 ; you can replace the LDX#$7/ASL with LDX# | ||
+ | ; asl ; to compute values up to 63 (as for a clock) | ||
+ | ; asl | ||
+ | sta < | ||
+ | lda #$0 ; Ensure the result is clear 2c | ||
+ | sed ; Switch to decimal mode 2c | ||
+ | CnvBit_sb asl <BIN ; Shift out one bit 5c | | ||
+ | sta < | ||
+ | adc < | ||
+ | dex ; And repeat for next bit 2c | | ||
+ | bne CnvBit_sb ; | ||
+ | cld ; Back to binary 2c | ||
+ | rts ; All Done. | ||
+ | |||
+ | BIN .equ | ||
+ | BCD0 .equ | ||
+ | </ | ||
+ | |||
Here is an equivalent routine for converting 16-bit numbers: | Here is an equivalent routine for converting 16-bit numbers: | ||
< | < |
base/more_hexadecimal_to_decimal_conversion.txt · Last modified: 2019-08-16 01:44 by verz