1
/* Copyright (c) 2006, Carlos Lamas
3
based on libc/pmstring/strlen_P.S which is
4
Copyright (c) 2002, Marek Michalkiewicz
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright
14
notice, this list of conditions and the following disclaimer in
15
the documentation and/or other materials provided with the
17
* Neither the name of the copyright holders nor the names of
18
contributors may be used to endorse or promote products derived
19
from this software without specific prior written permission.
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
POSSIBILITY OF SUCH DAMAGE. */
33
/* $Id: strlen_PF.S 2191 2010-11-05 13:45:57Z arcanum $ */
35
#if !defined(__AVR_TINY__)
39
#define src_b3 r25 /* MSB, ignored */
44
/** \ingroup avr_pgmspace
45
\fn size_t strlen_PF (uint_farptr_t s)
46
\brief Obtain the length of a string
48
The strlen_PF() function is similar to strlen(), except that \e s is a
49
far pointer to a string in program space
51
\param s A far pointer to the string in flash
53
\returns The strlen_PF() function returns the number of characters in
54
\e s. The contents of RAMPZ SFR are undefined when the function returns */
56
#if !defined(__DOXYGEN__)
60
.type _U(strlen_PF), @function
64
LPM_R0_ZPLUS_INIT src_b2
69
LPM_R0_ZPLUS_NEXT src_b2
71
brne .L_strlen_PF_loop
73
; return RAMPZ:Z - 1 - src = (-1 - src) + RAMPZ:Z = ~src + RAMPZ:Z
79
X_movw src_b2, src_b0 ; size_t is 16 bits
84
.size _U(strlen_PF), .L_strlen_PF_end - _U(strlen_PF)
86
#endif /* not __DOXYGEN__ */
88
#endif /* !defined(__AVR_TINY__) */