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

Diff of /avr-libc/libc/stdlib/atoi.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$ */
    $Id$  
30    
31     /*
32     Contributors:     Contributors:
33       Created by Reiner Patommel       Created by Reiner Patommel
34       Changes: Jochen Pernsteiner, Marek Michalkiewicz       Changes: Jochen Pernsteiner, Marek Michalkiewicz
# Line 72  Line 72 
72   */   */
73    
74  _U(atoi):  _U(atoi):
75          LOAD_Z  (str_lo, str_hi)        ; set pointer to string          X_movw  ZL, str_lo              ; set pointer to string
76          CLR     num_lo          CLR     num_lo
77          CLR     num_hi                  ; clear number          CLR     num_hi                  ; clear number
78          CLT                             ; clear sign flag          CLT                             ; clear sign flag
79    
80  .atoi_loop:  .L_atoi_loop:
81          LD      tmp, Z+                 ; get (next) character          LD      tmp, Z+                 ; get (next) character
82          TST     tmp                     ; is it end of string?          TST     tmp                     ; is it end of string?
83          BREQ    .atoi_sig          BREQ    .L_atoi_sig
84          CPI     tmp, ' '                ; skip whitespace          CPI     tmp, ' '                ; skip whitespace
85          BREQ    .atoi_loop          BREQ    .L_atoi_loop
86          CPI     tmp, '\t'          CPI     tmp, '\t'
87          BREQ    .atoi_loop          BREQ    .L_atoi_loop
88          CPI     tmp, '\n'          CPI     tmp, '\n'
89          BREQ    .atoi_loop          BREQ    .L_atoi_loop
90          CPI     tmp, '\f'          CPI     tmp, '\f'
91          BREQ    .atoi_loop          BREQ    .L_atoi_loop
92          CPI     tmp, '\r'          CPI     tmp, '\r'
93          BREQ    .atoi_loop          BREQ    .L_atoi_loop
94          CPI     tmp, '\v'          CPI     tmp, '\v'
95          BREQ    .atoi_loop          BREQ    .L_atoi_loop
96          CPI     tmp, '+'                ; if '+' convert          CPI     tmp, '+'                ; if '+' convert
97          BREQ    .atoi_loop2          BREQ    .L_atoi_loop2
98          CPI     tmp, '-'                ; if '-' remember sign          CPI     tmp, '-'                ; if '-' remember sign
99          BRNE    .atoi_digit          BRNE    .L_atoi_digit
100    
101  .atoi_neg:  .L_atoi_neg:
102          SET                             ; remember number is negative          SET                             ; remember number is negative
103    
104  .atoi_loop2:  .L_atoi_loop2:
105          LD      tmp, Z+          LD      tmp, Z+
106          TST     tmp          TST     tmp
107          BREQ    .atoi_sig          BREQ    .L_atoi_sig
108    
109  .atoi_digit:  .L_atoi_digit:
110          CPI     tmp, '0'                ; test on [0 .. 9]          CPI     tmp, '0'                ; test on [0 .. 9]
111          BRLT    .atoi_sig          BRLT    .L_atoi_sig
112          CPI     tmp, '9'+1          CPI     tmp, '9'+1
113          BRGE    .atoi_sig          BRGE    .L_atoi_sig
114          SUBI    tmp, '0'                ; make figure a number          SUBI    tmp, '0'                ; make figure a number
115          XCALL   __mulhi_const_10        ; r25:r24 *= 10          XCALL   __mulhi_const_10        ; r25:r24 *= 10
116          ADD     num_lo, tmp             ; num = (num * 10) + (tmp - '0')          ADD     num_lo, tmp             ; num = (num * 10) + (tmp - '0')
117          ADC     num_hi, __zero_reg__          ADC     num_hi, __zero_reg__
118          RJMP    .atoi_loop2             ; next figure          RJMP    .L_atoi_loop2           ; next figure
119    
120  .atoi_sig:  .L_atoi_sig:
121          CP      num_lo, __zero_reg__          CP      num_lo, __zero_reg__
122          CPC     num_hi, __zero_reg__    ; did we get a number?          CPC     num_hi, __zero_reg__    ; did we get a number?
123          BREQ    .atoi_done              ; no, drop sign and return          BREQ    .L_atoi_done            ; no, drop sign and return
124          BRTC    .atoi_done              ; positive number? -> return          BRTC    .L_atoi_done            ; positive number? -> return
125          COM     num_lo          COM     num_lo
126          COM     num_hi          COM     num_hi
127          ADIW    num_lo, 1               ; make number negative          ADIW    num_lo, 1               ; make number negative
128    
129  .atoi_done:  .L_atoi_done:
130          RET          RET
131    
132  .atoi_end:  .L_atoi_end:
133          .size _U(atoi), .atoi_end - _U(atoi)          .size _U(atoi), .L_atoi_end - _U(atoi)
134    
135  #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