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

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.7.4.1

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