base:another_hexadecimal_to_decimal_conversion
This is an old revision of the document!
Another Hexadecimal to Decimal Conversion
by Mace
Garth Wilson used decimal mode in Hexadecimal to Decimal Conversion and the result was in 3 bytes in decimal mode. I needed plain ASCII, the following routine does just that, using more or less the same method as Garth used:
start: lda #$30 // clear the result buffer ldy #$00 clear: sta result,y iny cpy #$05 bne clear ldx #$4f loop1: clc rol lobyte rol hibyte bcs calculate // when bit drops off, decimal value must be added // if not, go to the next bit txa axs #$05 // ILLEGAL OPCODE, alternatively use lines below // sec // sbc #$05 // tax bpl loop1 END: rts calculate: clc ldy #$04 loop2: lda table,x // get decimal equivalent of bit in ASCII numbers adc #$00 // add carry, is set if the former addition >10 beq zero // skip (speed up) when there's nothing to add adc result,y // add to whatever result we alread haven cmp #$3a // passing 10 with the addition? bcc notten sbc #$0a // if so, subtract 10 notten: sta result,y zero: dex dey bpl loop2 // loop until all 5 digits have been jmp loop1 table: .byte 0,0,0,0,1 .byte 0,0,0,0,2 .byte 0,0,0,0,4 .byte 0,0,0,0,8 .byte 0,0,0,1,6 .byte 0,0,0,3,2 .byte 0,0,0,6,4 .byte 0,0,1,2,8 .byte 0,0,2,5,6 .byte 0,0,5,1,2 .byte 0,1,0,2,4 .byte 0,2,0,4,8 .byte 0,4,0,9,6 .byte 0,8,1,9,2 .byte 1,6,3,8,4 .byte 3,2,7,6,8 result: .byte 0,0,0,0,0 lobyte: .byte 11 hibyte: .byte 0
base/another_hexadecimal_to_decimal_conversion.1605300711.txt.gz · Last modified: 2020-11-13 21:51 by mace