/[avr-libc]/avr-libc/libc/stdlib/atol.S
ViewVC logotype

Diff of /avr-libc/libc/stdlib/atol.S

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by joerg_wunsch, Tue Sep 13 13:29:54 2005 UTC revision 1.9 by aesok, Wed Nov 9 23:51:43 2005 UTC
# Line 26  Line 26 
26    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27    POSSIBILITY OF SUCH DAMAGE. */    POSSIBILITY OF SUCH DAMAGE. */
28    
29    /* $Id$ */
30    
31  /*  /*
32     atol.S     atol.S
33    
# Line 73  Line 75 
75    
76  _U(atol):  _U(atol):
77          PUSH    r17          PUSH    r17
78          LOAD_Z  (str_lo, str_hi)        ; set pointer to string          X_movw  ZL, str_lo              ; set pointer to string
79          CLR     num_hi_hi          CLR     num_hi_hi
80          CLR     num_hi_lo          CLR     num_hi_lo
81          CLR     num_lo_hi          CLR     num_lo_hi
82          CLR     num_lo_lo               ; clear number          CLR     num_lo_lo               ; clear number
83          CLT                             ; clear sign          CLT                             ; clear sign
84    
85  .atol_loop:  .L_atol_loop:
86          LD      tmp, Z+                 ; get (next) character          LD      tmp, Z+                 ; get (next) character
87          TST     tmp                     ; is it end of string?          TST     tmp                     ; is it end of string?
88          BREQ    .atol_sig          BREQ    .L_atol_sig
89          CPI     tmp, ' '                ; skip whitespace          CPI     tmp, ' '                ; skip whitespace
90          BREQ    .atol_loop          BREQ    .L_atol_loop
91          CPI     tmp, '\t'          CPI     tmp, '\t'
92          BREQ    .atol_loop          BREQ    .L_atol_loop
93          CPI     tmp, '\n'          CPI     tmp, '\n'
94          BREQ    .atol_loop          BREQ    .L_atol_loop
95          CPI     tmp, '\f'          CPI     tmp, '\f'
96          BREQ    .atol_loop          BREQ    .L_atol_loop
97          CPI     tmp, '\r'          CPI     tmp, '\r'
98          BREQ    .atol_loop          BREQ    .L_atol_loop
99          CPI     tmp, '\v'          CPI     tmp, '\v'
100          BREQ    .atol_loop          BREQ    .L_atol_loop
101          CPI     tmp, '+'                ; if '+' go on          CPI     tmp, '+'                ; if '+' go on
102          BREQ    .atol_loop2          BREQ    .L_atol_loop2
103          CPI     tmp, '-'                ; if '-' remember sign          CPI     tmp, '-'                ; if '-' remember sign
104          BRNE    .atol_digit          BRNE    .L_atol_digit
105    
106  .atol_neg:  .L_atol_neg:
107          SET                             ; remember number is negative          SET                             ; remember number is negative
108    
109  .atol_loop2:  .L_atol_loop2:
110          LD      tmp, Z+          LD      tmp, Z+
111          TST     tmp          TST     tmp
112          BREQ    .atol_sig          BREQ    .L_atol_sig
113    
114  .atol_digit:  .L_atol_digit:
115          CPI     tmp, '0'                ; test on [0 .. 9]          CPI     tmp, '0'                ; test on [0 .. 9]
116          BRLT    .atol_sig          BRLT    .L_atol_sig
117          CPI     tmp, '9'+1          CPI     tmp, '9'+1
118          BRGE    .atol_sig          BRGE    .L_atol_sig
119          SUBI    tmp, '0'                ; make figure a number          SUBI    tmp, '0'                ; make figure a number
120          XCALL   __mulsi_const_10        ; r25:r24:r23:r22 *= 10          XCALL   __mulsi_const_10        ; r25:r24:r23:r22 *= 10
121          ADD     num_lo_lo, tmp          ; num = (num * 10) + (tmp - '0')          ADD     num_lo_lo, tmp          ; num = (num * 10) + (tmp - '0')
122          ADC     num_lo_hi, __zero_reg__          ADC     num_lo_hi, __zero_reg__
123          ADC     num_hi_lo, __zero_reg__          ADC     num_hi_lo, __zero_reg__
124          ADC     num_hi_hi, __zero_reg__          ADC     num_hi_hi, __zero_reg__
125          RJMP    .atol_loop2             ; next figure          RJMP    .L_atol_loop2           ; next figure
126    
127  .atol_sig:  .L_atol_sig:
128          CP      num_lo_lo, __zero_reg__          CP      num_lo_lo, __zero_reg__
129          CPC     num_lo_hi, __zero_reg__          CPC     num_lo_hi, __zero_reg__
130          CPC     num_hi_lo, __zero_reg__          CPC     num_hi_lo, __zero_reg__
131          CPC     num_hi_hi, __zero_reg__ ; did we get a number?          CPC     num_hi_hi, __zero_reg__ ; did we get a number?
132          BREQ    .atol_done              ; no, drop sign and return          BREQ    .L_atol_done            ; no, drop sign and return
133          BRTC    .atol_done              ; positive number? -> return          BRTC    .L_atol_done            ; positive number? -> return
134          COM     num_hi_hi          COM     num_hi_hi
135          COM     num_hi_lo          COM     num_hi_lo
136          COM     num_lo_hi          COM     num_lo_hi
# Line 137  _U(atol): Line 139  _U(atol):
139          SBCI    num_hi_lo, 0xff          SBCI    num_hi_lo, 0xff
140          SBCI    num_hi_hi, 0xff         ; make number negative          SBCI    num_hi_hi, 0xff         ; make number negative
141    
142  .atol_done:  .L_atol_done:
143          POP     r17          POP     r17
144          RET          RET
145    
146  .atol_end:  .L_atol_end:
147          .size _U(atol), .atol_end - _U(atol)          .size _U(atol), .L_atol_end - _U(atol)
148    
149  #endif /* not __DOXYGEN__ */  #endif /* not __DOXYGEN__ */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26