xref: /csrg-svn/lib/libc/vax/string/strncat.s (revision 17323)
1/*	strncat.s	4.1	84/11/01	*/
2
3/*
4 * Concatenate string s2 on the end of s1
5 * and return the base of s1.  The parameter
6 * n is the maximum length of string s2 to
7 * concatenate.
8 *
9 * char *
10 * strncat(s1, s2, n)
11 *	char *s1, *s2;
12 *	int n;
13 */
14	.globl	_strncat
15
16_strncat:
17	.word	0x40
18	movl	12(ap),r6	# r6 = n
19	bleq	done		# n <= 0
20	movl	4(ap),r3	# r3 = s1
21	movl	r3,r1
220:
23	locc	$0,$65535,(r1)
24	beql	0b
25	movl	r1,r3		# r3 = index(s1, '\0');
26	movl	8(ap),r1	# r1 = s2
271:
28	movzwl	$65535,r2	# r2 = bytes in first chunk
29	cmpl	r6,r2		# r2 = min(bytes in chunk, n);
30	jgeq	2f
31	movl	r6,r2
322:
33	subl2	r2,r6		# update n
34	locc	$0,r2,(r1)	# '\0' found?
35	jneq	3f
36	subl2	r2,r1		# back up pointer updated by locc
37	movc3	r2,(r1),(r3)	# copy in next piece
38	tstl	r6		# run out of space?
39	jneq	1b
40	clrb	(r3)		# force '\0' termination
41	jbr	done
423:
43	subl2	r0,r2		# r2 = number of bytes to move
44	subl2	r2,r1		# back up pointer updated by locc
45	incl	r2		# copy '\0' as well
46	movc3	r2,(r1),(r3)	# copy in last piece
47done:
48	movl	4(ap),r0	# return s1
49	ret
50