File: strncpy_P.S

package info (click to toggle)
avr-libc 20020203-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,448 kB
  • ctags: 6,562
  • sloc: ansic: 7,631; asm: 4,424; sh: 2,703; makefile: 338; pascal: 289
file content (42 lines) | stat: -rw-r--r-- 895 bytes parent folder | download
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

#include "macros.inc"

#define dest_hi r25
#define dest_lo r24
#define src_hi r23
#define src_lo r22
#define len_hi r21
#define len_lo r20

; char *strncpy_P(char *dest, const char flash *src, size_t len)

	.text
	.global	_U(strncpy_P)
	.type	_U(strncpy_P), @function
_U(strncpy_P):
	LOAD_Z(src_lo, src_hi)
	LOAD_X(dest_lo, dest_hi)
.strncpy_P_loop:
	subi	len_lo, lo8(1)
	sbci	len_hi, hi8(1)
	brcs	.strncpy_P_done
	LPM_R0_ZP
	st	X+, r0
	tst	r0
	brne	.strncpy_P_loop
; store null characters up to the end of dest
; as the glibc manual says:
; This behavior is rarely useful, but it is specified by the ISO C standard.
	rjmp	.strncpy_P_clr_start
.strncpy_P_clr_loop:
	st	X+, __zero_reg__
.strncpy_P_clr_start:
	subi	len_lo, lo8(1)
	sbci	len_hi, hi8(1)
	brcc	.strncpy_P_clr_loop
.strncpy_P_done:
; return dest (unchanged)
	ret
.strncpy_P_end:
	.size	_U(strncpy_P), .strncpy_P_end - _U(strncpy_P)