76
LOAD_Z (str_lo, str_hi) ; set pointer to string
78
X_movw ZL, str_lo ; set pointer to string
80
82
CLR num_lo_lo ; clear number
84
86
LD tmp, Z+ ; get (next) character
85
87
TST tmp ; is it end of string?
87
89
CPI tmp, ' ' ; skip whitespace
99
101
CPI tmp, '+' ; if '+' go on
101
103
CPI tmp, '-' ; if '-' remember sign
105
107
SET ; remember number is negative
113
115
CPI tmp, '0' ; test on [0 .. 9]
117
119
SUBI tmp, '0' ; make figure a number
118
120
XCALL __mulsi_const_10 ; r25:r24:r23:r22 *= 10
119
121
ADD num_lo_lo, tmp ; num = (num * 10) + (tmp - '0')
120
122
ADC num_lo_hi, __zero_reg__
121
123
ADC num_hi_lo, __zero_reg__
122
124
ADC num_hi_hi, __zero_reg__
123
RJMP .atol_loop2 ; next figure
125
RJMP .L_atol_loop2 ; next figure
126
128
CP num_lo_lo, __zero_reg__
127
129
CPC num_lo_hi, __zero_reg__
128
130
CPC num_hi_lo, __zero_reg__
129
131
CPC num_hi_hi, __zero_reg__ ; did we get a number?
130
BREQ .atol_done ; no, drop sign and return
131
BRTC .atol_done ; positive number? -> return
132
BREQ .L_atol_done ; no, drop sign and return
133
BRTC .L_atol_done ; positive number? -> return
137
139
SBCI num_hi_lo, 0xff
138
140
SBCI num_hi_hi, 0xff ; make number negative
145
.size _U(atol), .atol_end - _U(atol)
147
.size _U(atol), .L_atol_end - _U(atol)
147
#endif /* not DOXYGEN */
149
#endif /* not __DOXYGEN__ */