User Tools

Site Tools


base:another_hexadecimal_to_decimal_conversion

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
base:another_hexadecimal_to_decimal_conversion [2020-11-13 21:51]
mace shortened two bytes
base:another_hexadecimal_to_decimal_conversion [2020-11-14 23:05]
mace Shortened code, added more comments
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 34: Line 33:
 loop2: loop2:
  lda table,x // get decimal equivalent of bit in ASCII numbers  lda table,x // get decimal equivalent of bit in ASCII numbers
- adc #$00        // add carry, is set if the former addition >10+ adc #$00        // add carry, is set if the former addition 10
                 beq zero // skip (speed up) when there's nothing to add                 beq zero // skip (speed up) when there's nothing to add
- adc result,y // add to whatever result we alread haven + adc result,y // add to whatever result we already have 
- cmp #$3a // passing 10 with the addition? + cmp #$3a // 10 with the addition? 
- bcc notten + bcc notten      // if not, skip the subtraction 
- sbc #$0a // if so, subtract 10 + 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:                          // decimal values for every bit in 16-bit figure 
- .byte 0,0,0,0,1 + .byte 0,0,0,0,1 // %0000000000000001 
- .byte 0,0,0,0,2 + .byte 0,0,0,0,// %0000000000000010 
- .byte 0,0,0,0,4 + .byte 0,0,0,0,// %0000000000000100 
- .byte 0,0,0,0,8 + .byte 0,0,0,0,// %0000000000001000 
- .byte 0,0,0,1,6 + .byte 0,0,0,1,// %0000000000010000 
- .byte 0,0,0,3,2 + .byte 0,0,0,3,// %0000000000100000 
- .byte 0,0,0,6,4 + .byte 0,0,0,6,// %0000000001000000 
- .byte 0,0,1,2,8 + .byte 0,0,1,2,// %0000000010000000 
- .byte 0,0,2,5,6 + .byte 0,0,2,5,// %0000000100000000 
- .byte 0,0,5,1,2 + .byte 0,0,5,1,// %0000001000000000 
- .byte 0,1,0,2,4 + .byte 0,1,0,2,// %0000010000000000 
- .byte 0,2,0,4,8 + .byte 0,2,0,4,// %0000100000000000 
- .byte 0,4,0,9,6 + .byte 0,4,0,9,// %0001000000000000 
- .byte 0,8,1,9,2 + .byte 0,8,1,9,// %0010000000000000 
- .byte 1,6,3,8,4 + .byte 1,6,3,8,// %0100000000000000 
- .byte 3,2,7,6,8+ .byte 3,2,7,6,// %1000000000000000
  
 result: result:
- .byte 0,0,0,0,0+ .byte 0,0,0,0,// this is where the result will be
 lobyte: lobyte:
- .byte 11+ .byte $b3       // demonstration value
 hibyte: hibyte:
- .byte 0+ .byte $a9       // demonstration value
 </code> </code>
base/another_hexadecimal_to_decimal_conversion.txt · Last modified: 2020-11-14 23:05 by mace