2474
|
1 ****************************************
|
|
2
|
|
3 * DECIMAL to BINARY conversion routine
|
|
4
|
|
5 * OTHER MODULES NEEDED: DECTAB$, IS_TERMIN
|
|
6
|
|
7 * ENTRY: X = start of asci decimal string terminated by
|
|
8 * a space, comma, CR or null.
|
|
9
|
|
10 * EXIT: D = binary value
|
|
11 * CC carry set if error (too large, not numeric)
|
|
12 * Y = terminator or error char.
|
|
13
|
|
14 nam Convert Decimal String to Binary
|
|
15 ttl Assembler Library Module
|
|
16
|
|
17
|
|
18 psect DEC_BIN,0,0,0,0,0
|
|
19
|
|
20 vsect
|
|
21 nega rmb 1
|
|
22 endsect
|
|
23
|
|
24 DEC_BIN:
|
|
25 clra set result to 0
|
|
26 clrb
|
|
27 pshs a,b,x
|
|
28 leas -1,s temp variable
|
|
29
|
|
30 clr nega,u
|
|
31 ldb ,x+
|
|
32 cmpb #'-
|
|
33 bne decbn15
|
|
34 stb nega,u
|
|
35 decbn1
|
|
36 LDB ,X+ get a digit
|
|
37 decbn15
|
|
38 LBSR IS_DIGIT
|
|
39 bne decbn3 end of string...
|
|
40 INCA bump string len
|
|
41 BRA decbn1 loop for whole string
|
|
42
|
|
43 decbn3
|
|
44 lbsr IS_TERMIN valid terminator?
|
|
45 bne error
|
|
46
|
|
47 ok
|
|
48 TSTA length = 0?
|
|
49 BEQ error yes, error
|
|
50 CMPA #6 more than 6 chars?
|
|
51 BHI error yes, error
|
|
52
|
|
53 ldx 3,s get start of string again
|
|
54
|
|
55 PSHS A
|
|
56 lda ,x
|
|
57 cmpa #'-
|
|
58 bne decbn35
|
|
59 leax 1,x
|
|
60 decbn35
|
|
61 LDA #5 max length
|
|
62 SUBA ,S+ adjust for offset
|
|
63 ASLA 2 bytes per table entry
|
|
64 LEAY DECTAB$,PCR addr of conversion table
|
|
65 LEAY A,Y add in offset for actual len
|
|
66
|
|
67 decbn4
|
|
68 LDA ,X+ get a digit
|
|
69 SUBA #$30 strip off ASCII
|
|
70 BEQ decbn6 zero, skip
|
|
71 sta ,s save digit=# of adds
|
|
72 LDD 1,S get binary data
|
|
73
|
|
74 decbn5
|
|
75 ADDD ,Y add in table value
|
|
76 BCS error past 0, too big
|
|
77 DEC ,S count down digit size
|
|
78 BNE decbn5 loop til 0
|
|
79 STD 1,S save binary data
|
|
80
|
|
81
|
|
82 decbn6
|
|
83 LEAY 2,Y next entry
|
|
84 tst 1,y end of table?
|
|
85 BNE decbn4 loop til done
|
|
86 clr ,s+ clean up and clear carry
|
|
87 bra exit
|
|
88
|
|
89
|
|
90 error
|
|
91 clr 0,s force data = 0
|
|
92 clr 1,s
|
|
93 com ,s+ clean up and set carry
|
|
94
|
|
95 exit
|
|
96 tfr x,y end of string/error char
|
|
97 puls a,b,x
|
|
98 bcs leave
|
|
99 tst nega,u
|
|
100 beq leave
|
|
101 subd #$0001
|
|
102 coma
|
|
103 comb
|
|
104 andcc #$FE
|
|
105 leave
|
|
106 rts
|
|
107
|
|
108
|
|
109 endsect
|
|
110
|