~ubuntu-branches/ubuntu/feisty/avr-libc/feisty

« back to all changes in this revision

Viewing changes to libc/stdlib/atoi.S

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2006-11-15 21:12:47 UTC
  • mfrom: (3.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115211247-b7qhgnb6o49v5zsg
Tags: 1:1.4.5-2
* Convertion to debheler fixed (closes: #398220)
* Reference to /usr/share/common-licenses in copyright file

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
27
  POSSIBILITY OF SUCH DAMAGE. */  
28
28
 
29
 
/*
30
 
   $Id: atoi.S,v 1.7 2003/09/30 23:05:18 troth Exp $
 
29
/* $Id: atoi.S,v 1.9 2005/11/09 23:51:43 aesok Exp $ */
31
30
 
 
31
 /*
32
32
   Contributors:
33
33
     Created by Reiner Patommel
34
34
     Changes: Jochen Pernsteiner, Marek Michalkiewicz
58
58
           except that atoi() does not detect errors.      
59
59
*/
60
60
 
61
 
#if !defined(DOXYGEN)
 
61
#if !defined(__DOXYGEN__)
62
62
 
63
63
        .text
64
64
        .global _U(atoi)
72
72
 */
73
73
 
74
74
_U(atoi):
75
 
        LOAD_Z  (str_lo, str_hi)        ; set pointer to string
 
75
        X_movw  ZL, str_lo              ; set pointer to string
76
76
        CLR     num_lo
77
77
        CLR     num_hi                  ; clear number
78
78
        CLT                             ; clear sign flag
79
79
 
80
 
.atoi_loop:
 
80
.L_atoi_loop:
81
81
        LD      tmp, Z+                 ; get (next) character
82
82
        TST     tmp                     ; is it end of string?
83
 
        BREQ    .atoi_sig
 
83
        BREQ    .L_atoi_sig
84
84
        CPI     tmp, ' '                ; skip whitespace
85
 
        BREQ    .atoi_loop
 
85
        BREQ    .L_atoi_loop
86
86
        CPI     tmp, '\t'
87
 
        BREQ    .atoi_loop
 
87
        BREQ    .L_atoi_loop
88
88
        CPI     tmp, '\n'
89
 
        BREQ    .atoi_loop
 
89
        BREQ    .L_atoi_loop
90
90
        CPI     tmp, '\f'
91
 
        BREQ    .atoi_loop
 
91
        BREQ    .L_atoi_loop
92
92
        CPI     tmp, '\r'
93
 
        BREQ    .atoi_loop
 
93
        BREQ    .L_atoi_loop
94
94
        CPI     tmp, '\v'
95
 
        BREQ    .atoi_loop
 
95
        BREQ    .L_atoi_loop
96
96
        CPI     tmp, '+'                ; if '+' convert
97
 
        BREQ    .atoi_loop2
 
97
        BREQ    .L_atoi_loop2
98
98
        CPI     tmp, '-'                ; if '-' remember sign
99
 
        BRNE    .atoi_digit
 
99
        BRNE    .L_atoi_digit
100
100
 
101
 
.atoi_neg:
 
101
.L_atoi_neg:
102
102
        SET                             ; remember number is negative
103
103
 
104
 
.atoi_loop2:
 
104
.L_atoi_loop2:
105
105
        LD      tmp, Z+
106
106
        TST     tmp
107
 
        BREQ    .atoi_sig
 
107
        BREQ    .L_atoi_sig
108
108
 
109
 
.atoi_digit:
 
109
.L_atoi_digit:
110
110
        CPI     tmp, '0'                ; test on [0 .. 9]
111
 
        BRLT    .atoi_sig
 
111
        BRLT    .L_atoi_sig
112
112
        CPI     tmp, '9'+1
113
 
        BRGE    .atoi_sig
 
113
        BRGE    .L_atoi_sig
114
114
        SUBI    tmp, '0'                ; make figure a number
115
115
        XCALL   __mulhi_const_10        ; r25:r24 *= 10
116
116
        ADD     num_lo, tmp             ; num = (num * 10) + (tmp - '0')
117
117
        ADC     num_hi, __zero_reg__
118
 
        RJMP    .atoi_loop2             ; next figure
 
118
        RJMP    .L_atoi_loop2           ; next figure
119
119
 
120
 
.atoi_sig:
 
120
.L_atoi_sig:
121
121
        CP      num_lo, __zero_reg__
122
122
        CPC     num_hi, __zero_reg__    ; did we get a number?
123
 
        BREQ    .atoi_done              ; no, drop sign and return
124
 
        BRTC    .atoi_done              ; positive number? -> return
 
123
        BREQ    .L_atoi_done            ; no, drop sign and return
 
124
        BRTC    .L_atoi_done            ; positive number? -> return
125
125
        COM     num_lo
126
126
        COM     num_hi
127
127
        ADIW    num_lo, 1               ; make number negative
128
128
 
129
 
.atoi_done:
 
129
.L_atoi_done:
130
130
        RET
131
131
 
132
 
.atoi_end:
133
 
        .size _U(atoi), .atoi_end - _U(atoi)
 
132
.L_atoi_end:
 
133
        .size _U(atoi), .L_atoi_end - _U(atoi)
134
134
 
135
 
#endif /* not DOXYGEN */
 
135
#endif /* not __DOXYGEN__ */