File: strncpy.S

package info (click to toggle)
picolibc 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 31,616 kB
  • sloc: ansic: 312,308; asm: 22,739; perl: 2,414; sh: 1,619; python: 1,019; pascal: 329; exp: 287; makefile: 164; xml: 40; cpp: 10
file content (44 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Copyright (c) 2009 Nick Clifton <nickc@redhat.com>
 */
	.file	"strncpy.S"

	.section .text
	.global  _strncpy
	.type	 _strncpy,@function
_strncpy:
#ifdef __RX_DISALLOW_STRING_INSNS__
	cmp	#0, r3
	beq	3f
	
	mov	r1, r4		; Preserve R1 for the return value.

2:	mov.b	[r2+], r5	; Copy bytes until...
	mov.b	r5, [r4+]
	sub	#1, r3
	beq	3f		; ... our count reaches zero
	cmp	#0, r5
	bne	2b		; ... or we have written a NUL byte

4:	mov.b	r5, [r4+]	; Continue to write further NUL bytes
	sub	#1, r3
	bne	4b		; until the count reaches zero.

3:	rts
	
#else
	mov	r1, r4		; Save a copy of the dest pointer.
	mov	r3, r5		; Save a copy of the byte count
	smovu	    		; Copy the bytes
	cmp	#0, r3		; If we have copied the number of bytes requested
	beq	1f  		;  then skip the next bit:
	add	r4, r5, r1	; Point to the last byte that we are supposed to write.
	sub	r3, r1		; Subtract the number of bytes left to be written.
	mov	#0, r2		; Fill the remaining bytes with NULs,
	sstr.b
1:
	mov	r4, r1		; Return the destination pointer
	rts
#endif
	.size _strncpy, . - _strncpy