base:decimal_to_hexadecimal_conversion
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
base:decimal_to_hexadecimal_conversion [2015-04-17 04:31] – external edit 127.0.0.1 | base:decimal_to_hexadecimal_conversion [2016-02-14 21:59] – verz | ||
---|---|---|---|
Line 44: | Line 44: | ||
hiResult: | hiResult: | ||
loResult: | loResult: | ||
+ | |||
+ | |||
+ | |||
+ | By Verz: | ||
+ | |||
+ | I made a small improvement, | ||
+ | (Note that using a loResult in page zero there are 5 bytes/ | ||
+ | |||
+ | < | ||
+ | bcdbin | ||
+ | lda #$00 ; Init result bytes | ||
+ | ;sta loResult | ||
+ | sta hiResult | ||
+ | lda loInput | ||
+ | tay ; Save to Y | ||
+ | and #$f0 ; this two instructions, | ||
+ | lsr | ||
+ | ;alr #$f0 | ||
+ | sta loResult | ||
+ | lsr | ||
+ | lsr | ||
+ | adc loResult | ||
+ | sta loResult | ||
+ | tya | ||
+ | and #$0f ; Strip the ones | ||
+ | adc loResult | ||
+ | |||
+ | ldx hiInput | ||
+ | beq END ; No hundreds? Then go to end | ||
+ | HUND: clc | ||
+ | adc #$64 ; Add as many hundreds as value of X | ||
+ | bcc loop | ||
+ | inc hiResult | ||
+ | loop: dex | ||
+ | bne HUND | ||
+ | END: sta loResult | ||
+ | rts | ||
+ | |||
+ | hiInput: | ||
+ | loInput: | ||
+ | hiResult: | ||
+ | loResult: | ||
+ | |||
+ | |||
+ | |||
+ | Here a routine to convert a single BCD byte (0-99) in A, to a binary in A: | ||
+ | |||
+ | < | ||
+ | BCDBIN8 | ||
+ | tay | ||
+ | and # | ||
+ | lsr | ||
+ | ;alr # | ||
+ | sta pzTmp | ||
+ | lsr | ||
+ | lsr | ||
+ | adc pzTmp | ||
+ | sta pzTmp | ||
+ | tya | ||
+ | and # | ||
+ | adc pzTmp | ||
+ | rts | ||
+ | | ||
+ | pzTmp .equ $02 ; $02 is a unused zeropage memory location in C64 | ||
+ | |||
+ | </ | ||
+ |
base/decimal_to_hexadecimal_conversion.txt · Last modified: 2016-02-14 22:02 by verz