base:int16_and_uint16_conversion_to_string
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
base:int16_and_uint16_conversion_to_string [2019-08-16 17:23] – created verz | base:int16_and_uint16_conversion_to_string [2019-08-18 09:35] (current) – verz | ||
---|---|---|---|
Line 3: | Line 3: | ||
_UtoA converts an unsigned number\\ | _UtoA converts an unsigned number\\ | ||
The conversion is obtained via a BCD intermediate value. | The conversion is obtained via a BCD intermediate value. | ||
- | < | + | < |
bcd = $61 ; system Fac, 3 bytes | bcd = $61 ; system Fac, 3 bytes | ||
int16 = $64 ; system Fac, 2 bytes | int16 = $64 ; system Fac, 2 bytes | ||
Line 22: | Line 22: | ||
_ItoA | _ItoA | ||
- | lda int16+1 | + | |
+ | | ||
bpl _pos | bpl _pos | ||
- | _neg clc | + | _neg clc ; it's negative: let's 2complement it |
lda int16 | lda int16 | ||
eor #$ff | eor #$ff | ||
Line 34: | Line 35: | ||
adc #0 | adc #0 | ||
sta int16+1 | sta int16+1 | ||
- | | + | |
- | sta sgn | + | |
- | _pos jsr _UtoA | + | _pos |
+ | | ||
- | | + | |
- | beq _enditoa | + | beq _enditoa |
- | dex | + | dex ; adds ' |
sta CnvStr,x | sta CnvStr,x | ||
_enditoa | _enditoa | ||
Line 54: | Line 55: | ||
; | ; | ||
; | ; | ||
- | ; Call with 16 bit number in lobyte/ | + | ; Call with 16 bit number in int16 |
; | ; | ||
; | ; | ||
Line 60: | Line 61: | ||
_UtoA | _UtoA | ||
- | jsr BINBCD16_2 | + | jsr BINBCD16 |
;lda bcd+2 | ;lda bcd+2 | ||
- | and #$0f | + | and #$0f ; extracts every byte and adds $30 |
ora #$30 | ora #$30 | ||
sta CnvStr+1 | sta CnvStr+1 | ||
Line 95: | Line 96: | ||
ldx #1 ; remove 0s at beginning | ldx #1 ; remove 0s at beginning | ||
_rem0 lda CnvStr,x | _rem0 lda CnvStr,x | ||
- | cmp #$30 | + | cmp #$30 ; if it's a ' |
bne _rts | bne _rts | ||
lda #$20 ; put a space instead | lda #$20 ; put a space instead | ||
sta CnvStr, | sta CnvStr, | ||
inx | inx | ||
- | cpx #$5 | + | cpx #$5 ; exits before last digit |
bne _rem0 | bne _rem0 | ||
Line 113: | Line 114: | ||
; needs the pos of the first digit in .X | ; needs the pos of the first digit in .X | ||
; | ; | ||
+ | ; if the result is to be in CnvStr then change CnvTrm to CnvStr | ||
; | ; | ||
_TrimNum | _TrimNum | ||
Line 119: | Line 121: | ||
beq _rts | beq _rts | ||
_trmlp | _trmlp | ||
- | sta CnvTrm,y | + | sta CnvTrm, |
beq _rts | beq _rts | ||
inx | inx | ||
Line 129: | Line 131: | ||
; | ; | ||
- | ; Converts a 16bit number | + | ; Converts a 16bit number |
; | ; | ||
BINBCD16 | BINBCD16 | ||
Line 140: | Line 142: | ||
CBIT1 ASL int16 ; Shift out one bit 5 | CBIT1 ASL int16 ; Shift out one bit 5 | ||
ROL int16+1 | ROL int16+1 | ||
- | ; LDA bcd+0 ; And add into result | + | ; LDA bcd+0 ; |
- | ADC bcd+0 ; | + | ADC bcd+0 ; |
STA bcd+0 ; | STA bcd+0 ; | ||
- | ASL int16 ; | + | ASL int16 ; |
ROL int16+1 | ROL int16+1 | ||
ADC bcd+0 ; | ADC bcd+0 ; | ||
STA bcd+0 ; | STA bcd+0 ; | ||
- | ASL int16 ; | + | ASL int16 ; |
ROL int16+1 | ROL int16+1 | ||
ADC bcd+0 ; | ADC bcd+0 ; | ||
STA bcd+0 ; | STA bcd+0 ; | ||
- | ASL int16 ; | + | ASL int16 ; |
ROL int16+1 | ROL int16+1 | ||
ADC bcd+0 ; | ADC bcd+0 ; | ||
STA bcd+0 ; | STA bcd+0 ; | ||
- | ASL int16 ; | + | ASL int16 ; |
ROL int16+1 | ROL int16+1 | ||
ADC bcd+0 ; | ADC bcd+0 ; | ||
STA bcd+0 ; | STA bcd+0 ; | ||
- | ASL int16 ; | + | ASL int16 ; |
ROL int16+1 | ROL int16+1 | ||
ADC bcd+0 ; | ADC bcd+0 ; | ||
Line 196: | Line 198: | ||
usage example: | usage example: | ||
- | < | + | < |
Example | Example | ||
- | lda #0 | ||
- | sta sgn | ||
lda #$c0 | lda #$c0 | ||
sta int16 | sta int16 | ||
Line 211: | Line 211: | ||
- | lda #0 | ||
- | sta sgn | ||
lda #$c0 | lda #$c0 | ||
sta int16 | sta int16 |
base/int16_and_uint16_conversion_to_string.txt · Last modified: 2019-08-18 09:35 by verz