1/* Copyright (c) 2002, 2007 Marek Michalkiewicz
2   All rights reserved.
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions are met:
6
7   * Redistributions of source code must retain the above copyright
8     notice, this list of conditions and the following disclaimer.
9   * Redistributions in binary form must reproduce the above copyright
10     notice, this list of conditions and the following disclaimer in
11     the documentation and/or other materials provided with the
12     distribution.
13   * Neither the name of the copyright holders nor the names of
14     contributors may be used to endorse or promote products derived
15     from this software without specific prior written permission.
16
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  POSSIBILITY OF SUCH DAMAGE. */
28
29/* $Id: strchr.S 2191 2010-11-05 13:45:57Z arcanum $ */
30
31/** \file */
32
33/** \ingroup avr_string
34    \fn char *strchr(const char *src, int val)
35    \brief Locate character in string.
36
37    The strchr() function returns a pointer to the first occurrence of
38    the character \p val in the string \p src.
39
40    Here "character" means "byte" - these functions do not work with
41    wide or multi-byte characters.
42
43    \returns The strchr() function returns a pointer to the matched
44    character or \c NULL if the character is not found. */
45
46#if !defined(__AVR_TINY__)
47
48#if !defined(__DOXYGEN__)
49
50#include "macros.inc"
51
52#define src_hi r25
53#define src_lo r24
54; #define val_hi r23
55#define val_lo r22
56
57#define ret_hi r25
58#define ret_lo r24
59
60	ASSEMBLY_CLIB_SECTION
61	.global	_U(strchr)
62	.type	_U(strchr), @function
63_U(strchr):
64	X_movw	ZL, src_lo
65.L_strchr_loop:
66	ld	ret_lo, Z+
67	cp	ret_lo, val_lo
68	breq	.L_strchr_found
69	tst	ret_lo
70	brne	.L_strchr_loop
71; not found, return NULL pointer
72	clr	ret_hi
73	ret
74.L_strchr_found:
75	sbiw	ZL, 1		; undo post-increment
76	X_movw	ret_lo, ZL
77	ret
78.L_strchr_end:
79	.size	_U(strchr), .L_strchr_end - _U(strchr)
80
81#endif /* not __DOXYGEN__ */
82
83#endif /* !defined(__AVR_TINY__) */
84