1/*
2Copyright (c) 2009 Nick Clifton <nickc@redhat.com>
3 */
4#include <picolibc.h>
5
6	.file	"strcat.S"
7
8	.section .text
9	.global  _strcat
10	.type	 _strcat,@function
11_strcat:
12	;; On entry: r1 => Destination
13	;;           r2 => Source
14#ifdef __RX_DISALLOW_STRING_INSNS__
15	mov 	r1, r4		; Save a copy of the dest pointer.
16
171:	mov.b	[r4+], r5	; Find the NUL byte at the end of R4.
18	cmp	#0, r5
19	bne	1b
20
21	sub	#1, r4		; Move R4 back to point at the NUL byte.
22
232:	mov.b	[r2+], r5	; Copy bytes from R2 to R4 until we reach a NUL byte.
24	mov.b	r5, [r4+]
25	cmp	#0, r5
26	bne 	2b
27
28	rts
29#else
30	mov 	r1, r4		; Save a copy of the dest pointer.
31	mov 	r2, r5		; Save a copy of the source pointer.
32
33	mov	#0,  r2		; Search for the NUL byte.
34	mov 	#-1, r3		; Limit on the number of bytes examined.
35	suntil.b		; Find the end of the destination string.
36	sub	#1,  r1		; suntil.b leaves r1 pointing to the byte beyond the match.
37
38	mov	#-1, r3		; Set a limit on the number of bytes copied.
39	mov	r5,  r2		; Restore the source pointer.
40	smovu			; Copy source to destination
41
42	mov	r4, r1		; Return the original dest pointer.
43	rts
44#endif
45	.size _strcat, . - _strcat
46
47