Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TempOnes: .rs 2
- TempTens: .rs 2
- TempHund: .rs 2
- TempThous: .rs 2
- TempTenThous: .rs 2
- ;for example, let's use the following decimal numbers to convert to 16-bit binary
- ;13,268
- Math:
- LDX #$00
- LDA #$08 ;ones digit. You'd use $0201 for this or whatever the ones digit is in the code
- ASL A ;x2 to get to the hi byte of the correct digit
- LDA OnesDigit,x
- STA TempOnes
- INX
- LDA OnesDigit,x
- STA TempOnes+1
- LDX #$00
- LDA #$06
- ASL A
- LDA TensDigit,x
- STA TempTens
- INX
- LDA TensDigit,x
- STA TempTens+1
- LDX #$00
- LDA #$02
- ASL A
- LDA HundredsDigit,x
- STA TempHund
- INX
- LDA HundredsDigit,x
- STA TempHund+1
- LDX #$00
- LDA #$03
- ASL A
- LDA ThousandsDigit,x
- STA TempThous
- INX
- LDA ThousandsDigit,x
- STA TempThous+1
- LDX #$00
- LDA #$01
- ASL A
- LDA TenThousandsDigit,x
- STA TempTenThous
- INX
- LDA TenThousandsDigit,x
- STA TempTenThous+1
- ;;setup math is done
- LDA TempOnes+1 ;starting to add the bytes together, one digit at a time
- CLC ;this is ones+tens
- ADC TempTens+1
- STA TempOnes+1 ;this will be our recurring lowbyte addition value
- LDA TempOnes
- ADC TempTens
- STA TempOnes ;this will be our recurring hibyte addition value
- LDA TempOnes+1 ;this is ones+tens solution+hundreds
- CLC
- ADC TempHund+1
- STA TempOnes+1
- LDA TempOnes
- ADC TempHund
- STA TempOnes
- LDA TempOnes+1 ;previous solution+thousands
- CLC
- ADC TempThous+1
- STA TempOnes+1
- LDA TempOnes
- ADC TempThous
- STA TempOnes
- LDA TempOnes+1 ;previous solution+ten thousands
- CLC
- ADC TempTenThous+1
- STA TempOnes+1 ;TempOnes+1 is now your final low byte
- LDA TempOnes
- ADC TempTenThous
- STA TempOnes ;TempOnes is now your final hi byte
- RTS
- OnesDigit:
- .db $00,$00 ;0
- .db $00,$01 ;1
- .db $00,$02 ;2
- .db $00,$03 ;3
- .db $00,$04 ;4
- .db $00,$05 ;5
- .db $00,$06 ;6
- .db $00,$07 ;7
- .db $00,$08 ;8
- .db $00,$09 ;9
- TensDigit:
- .db $00,$00 ;00
- .db $00,$0A ;10
- .db $00,$14 ;20
- .db $00,$1E ;30
- .db $00,$28 ;40
- .db $00,$32 ;50
- .db $00,$3C ;60
- .db $00,$46 ;70
- .db $00,$50 ;80
- .db $00,$5A ;90
- HundredsDigit:
- .db $00,$00 ;000
- .db $00,$64 ;100
- .db $00,$C8 ;200
- .db $01,$2C ;300
- .db $01,$90 ;400
- .db $01,$F4 ;500
- .db $02,$58 ;600
- .db $02,$BC ;700
- .db $03,$20 ;800
- .db $03,$84 ;900
- ThousandsDigit:
- .db $00,$00 ;0000
- .db $03,$E8 ;1000
- .db $07,$D0 ;2000
- .db $0B,$B8 ;3000
- .db $0F,$A0 ;4000
- .db $13,$88 ;5000
- .db $17,$70 ;6000
- .db $1B,$58 ;7000
- .db $1F,$40 ;8000
- .db $23,$28 ;9000
- TenThousandsDigit:
- .db $00,$00 ;00000
- .db $27,$10 ;10000
- .db $4E,$20 ;20000
- .db $75,$30 ;30000
- .db $9C,$40 ;40000
- .db $C3,$50 ;50000
- .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