Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. TempOnes: .rs 2
  2. TempTens: .rs 2
  3. TempHund: .rs 2
  4. TempThous: .rs 2
  5. TempTenThous: .rs 2
  6.  
  7. ;for example, let's use the following decimal numbers to convert to 16-bit binary
  8. ;13,268
  9.  
  10. Math:
  11. LDX #$00
  12. LDA #$08 ;ones digit. You'd use $0201 for this or whatever the ones digit is in the code
  13. ASL A ;x2 to get to the hi byte of the correct digit
  14. LDA OnesDigit,x
  15. STA TempOnes
  16. INX
  17. LDA OnesDigit,x
  18. STA TempOnes+1
  19.  
  20. LDX #$00
  21. LDA #$06
  22. ASL A
  23. LDA TensDigit,x
  24. STA TempTens
  25. INX
  26. LDA TensDigit,x
  27. STA TempTens+1
  28.  
  29. LDX #$00
  30. LDA #$02
  31. ASL A
  32. LDA HundredsDigit,x
  33. STA TempHund
  34. INX
  35. LDA HundredsDigit,x
  36. STA TempHund+1
  37.  
  38. LDX #$00
  39. LDA #$03
  40. ASL A
  41. LDA ThousandsDigit,x
  42. STA TempThous
  43. INX
  44. LDA ThousandsDigit,x
  45. STA TempThous+1
  46.  
  47. LDX #$00
  48. LDA #$01
  49. ASL A
  50. LDA TenThousandsDigit,x
  51. STA TempTenThous
  52. INX
  53. LDA TenThousandsDigit,x
  54. STA TempTenThous+1
  55.  
  56. ;;setup math is done
  57.  
  58. LDA TempOnes+1 ;starting to add the bytes together, one digit at a time
  59. CLC ;this is ones+tens
  60. ADC TempTens+1
  61. STA TempOnes+1 ;this will be our recurring lowbyte addition value
  62. LDA TempOnes
  63. ADC TempTens
  64. STA TempOnes ;this will be our recurring hibyte addition value
  65.  
  66. LDA TempOnes+1 ;this is ones+tens solution+hundreds
  67. CLC
  68. ADC TempHund+1
  69. STA TempOnes+1
  70. LDA TempOnes
  71. ADC TempHund
  72. STA TempOnes
  73.  
  74. LDA TempOnes+1 ;previous solution+thousands
  75. CLC
  76. ADC TempThous+1
  77. STA TempOnes+1
  78. LDA TempOnes
  79. ADC TempThous
  80. STA TempOnes
  81.  
  82. LDA TempOnes+1 ;previous solution+ten thousands
  83. CLC
  84. ADC TempTenThous+1
  85. STA TempOnes+1 ;TempOnes+1 is now your final low byte
  86. LDA TempOnes
  87. ADC TempTenThous
  88. STA TempOnes ;TempOnes is now your final hi byte
  89. RTS
  90.  
  91. OnesDigit:
  92. .db $00,$00 ;0
  93. .db $00,$01 ;1
  94. .db $00,$02 ;2
  95. .db $00,$03 ;3
  96. .db $00,$04 ;4
  97. .db $00,$05 ;5
  98. .db $00,$06 ;6
  99. .db $00,$07 ;7
  100. .db $00,$08 ;8
  101. .db $00,$09 ;9
  102.  
  103. TensDigit:
  104. .db $00,$00 ;00
  105. .db $00,$0A ;10
  106. .db $00,$14 ;20
  107. .db $00,$1E ;30
  108. .db $00,$28 ;40
  109. .db $00,$32 ;50
  110. .db $00,$3C ;60
  111. .db $00,$46 ;70
  112. .db $00,$50 ;80
  113. .db $00,$5A ;90
  114.  
  115. HundredsDigit:
  116. .db $00,$00 ;000
  117. .db $00,$64 ;100
  118. .db $00,$C8 ;200
  119. .db $01,$2C ;300
  120. .db $01,$90 ;400
  121. .db $01,$F4 ;500
  122. .db $02,$58 ;600
  123. .db $02,$BC ;700
  124. .db $03,$20 ;800
  125. .db $03,$84 ;900
  126.  
  127. ThousandsDigit:
  128. .db $00,$00 ;0000
  129. .db $03,$E8 ;1000
  130. .db $07,$D0 ;2000
  131. .db $0B,$B8 ;3000
  132. .db $0F,$A0 ;4000
  133. .db $13,$88 ;5000
  134. .db $17,$70 ;6000
  135. .db $1B,$58 ;7000
  136. .db $1F,$40 ;8000
  137. .db $23,$28 ;9000
  138.  
  139. TenThousandsDigit:
  140. .db $00,$00 ;00000
  141. .db $27,$10 ;10000
  142. .db $4E,$20 ;20000
  143. .db $75,$30 ;30000
  144. .db $9C,$40 ;40000
  145. .db $C3,$50 ;50000
  146. .db $EA,$60 ;60000 ;this is as high as you can go for 16-bit math
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement