Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-------------------------------
- ; Converts a 16bit number to BCD
- ;-------------------------------
- BINBCD16
- SED ; Switch to decimal mode 2
- LDA #0 ; Ensure the result is clear 2
- STA bcd+0; 4
- STA bcd+1; 4
- STA bcd+2; 4 16
- LDX #6; 2 2
- CNVBIT1
- ASL lobyte ; Shift out one bit 6
- ROL hibyte ; 6
- ; LDA bcd+0 ; And add into result
- ADC bcd+0 ; 4
- STA bcd+0 ; 4
- ; LDA bcd+1 ; propagating any carry
- ; ADC bcd+1
- ; STA bcd+1
- ; LDA bcd+2 ; ... thru whole result
- ; ADC bcd+2
- ; STA bcd+2
- DEX ; And repeat for next bit 2
- BNE CNVBIT1 ; 3 25*6-1=149
- LDX #7; 2 2
- CNVBIT2
- ASL lobyte ; Shift out one bit 6
- ROL hibyte ; 6
- LDA bcd+0 ; And add into result 4
- ADC bcd+0 ; 4
- STA bcd+0 ; 4
- LDA bcd+1 ; propagating any carry 4
- ADC bcd+1 ; 4
- STA bcd+1 ; 4
- ; LDA bcd+2 ; ... thru whole result
- ; ADC bcd+2
- ; STA bcd+2
- DEX ; And repeat for next bit 2
- BNE CNVBIT2 ; 3 41*7-1=286
- LDX #3; 2 2
- CNVBIT3
- ASL lobyte ; Shift out one bit 6
- ROL hibyte ; 6
- LDA bcd+0 ; And add into result 4
- ADC bcd+0 ; 4
- STA bcd+0 ; 4
- LDA bcd+1 ; propagating any carry 4
- ADC bcd+1 ; 4
- STA bcd+1 ; 4
- LDA bcd+2 ; ... thru whole result 4
- ADC bcd+2 ; 4
- STA bcd+2 ; 4
- DEX ; And repeat for next bit 2
- BNE CNVBIT3 ; 3 53*3-1=158
- CLD ; Back to binary 2 2; tot 615
- rts ; All Done.
- bcd byte 0,0,0
- lobyte byte 0
- hibyte byte 0
- ; takes 615+rts cycles. If variables are in page zero (bcd and lobyte/hibyte), it goes down to 499 cycles.
- ; bcd = $a3
- ; lobyte = $2
- ; hibyte = $3
Add Comment
Please, Sign In to add comment