Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / _strlen.c
1 /*-------------------------------------------------------------------------
2   _strlen.c - part of string library functions
3
4              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
5                            mcs51 assembler by Frieder Ferlemann (2007)
6
7    This library is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Library General Public License as published by the
9    Free Software Foundation; either version 2, or (at your option) any
10    later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21    In other words, you are welcome to use, share and improve this program.
22    You are forbidden to forbid anyone else to use, share and improve
23    what you give them.   Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
25
26 #if (!defined (SDCC_mcs51))
27
28   /* Generic routine first */
29   int strlen ( char * str )
30   {
31     register int i = 0 ;
32
33     while (*str++)
34       i++ ;
35
36     return i;
37   }
38
39 #else
40
41   /* Assembler version for mcs51 */
42   int strlen ( char * str ) __naked
43   {
44     str;     /* hush the compiler */
45
46     __asm
47       ; dptr holds pointer
48       ; b holds pointer memspace
49       ;
50
51       ; char *ptr = str:
52       mov     r2,dpl
53       mov     r3,dph
54       ;
55
56       ; while ( *ptr ) ptr++;
57     L00101$:
58       lcall   __gptrget
59       jz      L00102$
60       inc     dptr
61       sjmp    L00101$
62       ;
63
64     L00102$:
65       ; return ptr - str;
66       clr     c
67       mov     a,dpl
68       subb    a,r2
69       mov     dpl,a
70       ;
71       mov     a,dph
72       subb    a,r3
73       mov     dph,a
74       ;
75       ret
76     __endasm;
77   }
78
79 #endif