~ubuntu-branches/ubuntu/gutsy/avr-libc/gutsy

« back to all changes in this revision

Viewing changes to libc/stdlib/atol.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
/* $Id: atol.S,v 1.9 2005/11/09 23:51:43 aesok Exp $ */
 
30
 
29
31
/*
30
32
   atol.S
31
33
 
59
61
           except that atol() does not detect errors.
60
62
*/
61
63
 
62
 
#if !defined(DOXYGEN)
 
64
#if !defined(__DOXYGEN__)
63
65
 
64
66
        .text
65
67
        .global _U(atol)
73
75
 
74
76
_U(atol):
75
77
        PUSH    r17
76
 
        LOAD_Z  (str_lo, str_hi)        ; set pointer to string
 
78
        X_movw  ZL, str_lo              ; set pointer to string
77
79
        CLR     num_hi_hi
78
80
        CLR     num_hi_lo
79
81
        CLR     num_lo_hi
80
82
        CLR     num_lo_lo               ; clear number
81
83
        CLT                             ; clear sign
82
84
 
83
 
.atol_loop:
 
85
.L_atol_loop:
84
86
        LD      tmp, Z+                 ; get (next) character
85
87
        TST     tmp                     ; is it end of string?
86
 
        BREQ    .atol_sig
 
88
        BREQ    .L_atol_sig
87
89
        CPI     tmp, ' '                ; skip whitespace
88
 
        BREQ    .atol_loop
 
90
        BREQ    .L_atol_loop
89
91
        CPI     tmp, '\t'
90
 
        BREQ    .atol_loop
 
92
        BREQ    .L_atol_loop
91
93
        CPI     tmp, '\n'
92
 
        BREQ    .atol_loop
 
94
        BREQ    .L_atol_loop
93
95
        CPI     tmp, '\f'
94
 
        BREQ    .atol_loop
 
96
        BREQ    .L_atol_loop
95
97
        CPI     tmp, '\r'
96
 
        BREQ    .atol_loop
 
98
        BREQ    .L_atol_loop
97
99
        CPI     tmp, '\v'
98
 
        BREQ    .atol_loop
 
100
        BREQ    .L_atol_loop
99
101
        CPI     tmp, '+'                ; if '+' go on
100
 
        BREQ    .atol_loop2
 
102
        BREQ    .L_atol_loop2
101
103
        CPI     tmp, '-'                ; if '-' remember sign
102
 
        BRNE    .atol_digit
 
104
        BRNE    .L_atol_digit
103
105
 
104
 
.atol_neg:
 
106
.L_atol_neg:
105
107
        SET                             ; remember number is negative
106
108
 
107
 
.atol_loop2:
 
109
.L_atol_loop2:
108
110
        LD      tmp, Z+
109
111
        TST     tmp
110
 
        BREQ    .atol_sig
 
112
        BREQ    .L_atol_sig
111
113
 
112
 
.atol_digit:
 
114
.L_atol_digit:
113
115
        CPI     tmp, '0'                ; test on [0 .. 9]
114
 
        BRLT    .atol_sig
 
116
        BRLT    .L_atol_sig
115
117
        CPI     tmp, '9'+1
116
 
        BRGE    .atol_sig
 
118
        BRGE    .L_atol_sig
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
124
126
 
125
 
.atol_sig:
 
127
.L_atol_sig:
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
132
134
        COM     num_hi_hi
133
135
        COM     num_hi_lo
134
136
        COM     num_lo_hi
137
139
        SBCI    num_hi_lo, 0xff
138
140
        SBCI    num_hi_hi, 0xff         ; make number negative
139
141
 
140
 
.atol_done:
 
142
.L_atol_done:
141
143
        POP     r17
142
144
        RET
143
145
 
144
 
.atol_end:
145
 
        .size _U(atol), .atol_end - _U(atol)
 
146
.L_atol_end:
 
147
        .size _U(atol), .L_atol_end - _U(atol)
146
148
 
147
 
#endif /* not DOXYGEN */
 
149
#endif /* not __DOXYGEN__ */