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