1/* Copyright (c) 2006, Carlos Lamas
2
3   based on libc/pmstring/strncat_P.S which is
4   Copyright (c) 2003, Reiner Patommel
5
6   based on strncat by Marek Michalkiewicz
7
8   All rights reserved.
9
10   Redistribution and use in source and binary forms, with or without
11   modification, are permitted provided that the following conditions are met:
12
13   * Redistributions of source code must retain the above copyright
14     notice, this list of conditions and the following disclaimer.
15   * Redistributions in binary form must reproduce the above copyright
16     notice, this list of conditions and the following disclaimer in
17     the documentation and/or other materials provided with the
18     distribution.
19   * Neither the name of the copyright holders nor the names of
20     contributors may be used to endorse or promote products derived
21     from this software without specific prior written permission.
22
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE. */
34
35/* $Id: strncat_PF.S 2503 2016-02-07 22:59:47Z joerg_wunsch $ */
36
37#if !defined(__AVR_TINY__)
38
39#include "macros.inc"
40
41#define dest_b1 r25
42#define dest_b0 r24
43#define src_b3 r23
44#define src_b2 r22
45#define src_b1 r21
46#define src_b0 r20
47#define len_b1 r19
48#define len_b0 r18
49
50#if !defined(__DOXYGEN__)
51
52	.text
53	.global	_U(strncat_PF)
54	.type	_U(strncat_PF), @function
55
56_U(strncat_PF):
57
58	X_movw	ZL, src_b0
59	LPM_R0_ZPLUS_INIT src_b2
60	X_movw	XL, dest_b0
61
62.L_strncat_PF_skip:
63
64	ld	r0, X+
65	tst	r0
66	brne	.L_strncat_PF_skip
67	sbiw	XL, 1		; undo post-increment (point the the NUL)
68
69.L_strncat_PF_loop:
70
71	subi	len_b0, lo8(1)
72	sbci	len_b1, hi8(1)
73	brcs	.L_strncat_PF_done
74	LPM_R0_ZPLUS_NEXT src_b2
75	tst	r0
76	st	X+, r0
77	brne	.L_strncat_PF_loop
78
79; return dest (unchanged)
80
81	ret
82
83.L_strncat_PF_done:
84
85	st	X, __zero_reg__
86
87; return dest (unchanged)
88
89	ret
90
91.L_strncat_PF_end:
92
93	.size	_U(strncat_PF), .L_strncat_PF_end - _U(strncat_PF)
94
95#endif /* not __DOXYGEN__ */
96
97#endif /* !defined(__AVR_TINY__) */
98