User Tools

Site Tools


base:32_bit_hexadecimal_to_decimal_conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

base:32_bit_hexadecimal_to_decimal_conversion [2015-04-17 04:30] (current)
Line 1: Line 1:
 +====== 32 bit hexadecimal to decimal conversion ======
 +
 +By Graham.
 +
 +In cases you need to print decimal values, you can use this routine to convert any unsigned 32 bit value to decimal. It doesn'​t use the BCD mode. The conversion is done by repeatedly dividing the 32 bit value by 10 and storing the remainder of each division as decimal digits.
 +
 +<​code> ​       ; prints a 32 bit value to the screen
 +printdec
 +        jsr hex2dec
 +
 +        ldx #9
 +l1      lda result,x
 +        bne l2
 +        dex             ; skip leading zeros
 +        bne l1
 +
 +l2      lda result,x
 +        ora #$30
 +        jsr $ffd2
 +        dex
 +        bpl l2
 +        rts
 +
 +        ; converts 10 digits (32 bit values have max. 10 decimal digits)
 +hex2dec
 +        ldx #0
 +l3      jsr div10
 +        sta result,x
 +        inx
 +        cpx #10
 +        bne l3
 +        rts
 +
 +        ; divides a 32 bit value by 10
 +        ; remainder is returned in akku
 +div10
 +        ldy #32         ; 32 bits
 +        lda #0
 +        clc
 +l4      rol
 +        cmp #10
 +        bcc skip
 +        sbc #10
 +skip    rol value
 +        rol value+1
 +        rol value+2
 +        rol value+3
 +        dey
 +        bpl l4
 +        rts
 +
 +value   .byte $ff,​$ff,​$ff,​$ff
 +
 +result ​ .byte 0,​0,​0,​0,​0,​0,​0,​0,​0,​0
 +</​code>​
  
base/32_bit_hexadecimal_to_decimal_conversion.txt ยท Last modified: 2015-04-17 04:30 (external edit)