base:another_hexadecimal_to_decimal_conversion
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
base:another_hexadecimal_to_decimal_conversion [2015-04-17 04:30] – external edit 127.0.0.1 | base:another_hexadecimal_to_decimal_conversion [2020-11-14 23:05] (current) – Shortened code, added more comments mace | ||
---|---|---|---|
Line 7: | Line 7: | ||
start: | start: | ||
lda #$30 // clear the result buffer | lda #$30 // clear the result buffer | ||
- | ldy #$00 | + | ldy #$04 |
clear: | clear: | ||
sta result,y | sta result,y | ||
- | iny | + | dey |
- | cpy #$05 | + | bcs clear |
- | bne clear | + | |
ldx #$4f | ldx #$4f | ||
loop1: | loop1: | ||
Line 18: | Line 17: | ||
rol lobyte | rol lobyte | ||
rol hibyte | rol hibyte | ||
- | bcs calculate // | + | bcs calculate // |
// if not, go to the next bit | // if not, go to the next bit | ||
txa | txa | ||
- | axs #$05 // ILLEGAL OPCODE, use the 3 lines below as alternative | + | axs #$05 // ILLEGAL OPCODE, |
// sec | // sec | ||
// sbc #$05 | // sbc #$05 | ||
// tax | // tax | ||
- | cpx #$ff | + | bpl loop1 |
- | bne loop1 | + | |
END: | END: | ||
rts | rts | ||
Line 34: | Line 32: | ||
ldy #$04 | ldy #$04 | ||
loop2: | loop2: | ||
- | lda table,x // get the decimal equivalent of the bit in ASCII numbers | + | lda table,x // get decimal equivalent of bit in ASCII numbers |
- | beq zero // skip (speed up) when there' | + | adc #$00 // add carry, is set if the former addition ≥10 |
- | adc result,y // add to whatever result we alread haven | + | |
- | cmp # | + | adc result,y // add to whatever result we already have |
- | bcc notten | + | cmp # |
- | sbc # | + | bcc notten |
+ | sbc #$0a // subtract 10 | ||
notten: | notten: | ||
sta result,y | sta result,y | ||
Line 47: | Line 46: | ||
bpl loop2 // loop until all 5 digits have been | bpl loop2 // loop until all 5 digits have been | ||
jmp loop1 | jmp loop1 | ||
- | table: | + | table: |
- | .byte 0,0,0,0,1 | + | .byte 0,0,0,0,1 // %0000000000000001 |
- | .byte 0,0,0,0,2 | + | .byte 0, |
- | .byte 0,0,0,0,4 | + | .byte 0, |
- | .byte 0,0,0,0,8 | + | .byte 0, |
- | .byte 0,0,0,1,6 | + | .byte 0, |
- | .byte 0,0,0,3,2 | + | .byte 0, |
- | .byte 0,0,0,6,4 | + | .byte 0, |
- | .byte 0,0,1,2,8 | + | .byte 0, |
- | .byte 0,0,2,5,6 | + | .byte 0, |
- | .byte 0,0,5,1,2 | + | .byte 0, |
- | .byte 0,1,0,2,4 | + | .byte 0, |
- | .byte 0,2,0,4,8 | + | .byte 0, |
- | .byte 0,4,0,9,6 | + | .byte 0, |
- | .byte 0,8,1,9,2 | + | .byte 0, |
- | .byte 1,6,3,8,4 | + | .byte 1, |
- | .byte 3,2,7,6,8 | + | .byte 3, |
result: | result: | ||
- | .byte 0,0,0,0,0 | + | .byte 0, |
lobyte: | lobyte: | ||
- | .byte | + | .byte |
hibyte: | hibyte: | ||
- | .byte | + | .byte |
</ | </ |
base/another_hexadecimal_to_decimal_conversion.1429237827.txt.gz · Last modified: 2015-04-17 04:30 by 127.0.0.1