]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/string-extras-asm.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / string-extras-asm.S
1 /* string-extras-asm.S */
2 /*
3     This file is part of the AVR-Huffman.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "avr-asm-macros.S"
21
22 /******************************************************************************/
23 /*
24         uint16_t stridentcnt_P(char *a, PGM_P b){
25                 uint16_t i=0;
26                 char c;
27                 for(;;){
28                         c = pgm_read_byte(b++);
29                         if(*a != c || c=='\0')
30                                 return i;
31                         i++;
32                         a++;
33                 }
34         }
35         
36         param a: r24:r25
37         param b: r22:r23
38 */      
39 .global stridentcnt_P
40 stridentcnt_P:
41         movw r30, r22
42         movw r26, r24
43         clr r24
44         clr r25
45 1:
46         ld r22, X+
47         lpm r23, Z+
48         cpse r22, r23
49 2:      ret
50         tst r22
51         breq 2b
52         adiw r24, 1
53         rjmp 1b
54                 
55
56 /******************************************************************************/
57 /*
58         uint16_t firstword_length(char *s){
59                 uint16_t ret=0;
60                 while(isgraph(*s++))
61                         ret++;
62                 return ret; 
63         }
64         
65         param s: r24:r25
66 */
67 .global firstword_length
68 firstword_length:
69         push r28
70         push r29
71         push r2
72         push r3
73         movw r2, r24
74         movw r28, r24
75 1:
76         clr r25
77         ld r24, Y+
78         call isgraph
79         adiw r24, 0
80         brne 1b
81         movw r24, r28
82         sbiw r24, 1
83         sub r24, r2
84         sbc r25, r3     
85         pop r3
86         pop r2
87         pop r29
88         pop r28
89         ret
90
91
92 /******************************************************************************/
93 /*
94         char *strstrip(char *str){
95                 if(!str)
96                         return str;
97                 char *endptr;
98                 while(*str && (*str==' ' || *str=='\t'))
99                         ++str;
100                 endptr=str;
101                 while(*endptr)
102                         ++endptr;
103                 do{
104                         --endptr;
105                 }while(*endptr==' ' || *endptr=='\t');
106                 endptr[1]='\0';
107                 return str;
108         }
109   
110   param str: r24:r25
111 */
112 .global strstrip
113 strstrip:
114         movw r26, r24
115         adiw r26, 0
116         breq 9f
117 1:
118         ld r22, X+
119         cpi r22, ' '
120         breq 1b
121         cpi r22, '\t'
122         breq 1b
123         sbiw r26, 1
124         movw r30, r26
125 2:
126         ld r22, Z+
127         tst r22
128         brne 2b
129 3:      
130         ld r22, -Z
131         cpi r22, ' '
132         breq 3b
133         cpi r22, '\t'
134         breq 3b
135         st Z, r1
136         movw r24, r26
137 9:
138         ret