summaryrefslogtreecommitdiffstats
path: root/private/crt32/string/i386/memccpy.asm
blob: 728f4ce23ceb53013dc01710727cb54b8465d356 (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	page	,132
	title	memccpy - copy bytes until character found
;***
;memccpy.asm - copy bytes until a character is found
;
;	Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved.
;
;Purpose:
;	defines _memccpy() - copies bytes until a specifed character
;	is found, or a maximum number of characters have been copied.
;
;Revision History:
;	05-16-84  RN	initial version
;	05-17-88  SJM	Add model-independent (large model) ifdef
;	08-04-88  SJM	convert to cruntime/ add 32-bit support
;	08-23-88  JCR	Minor 386 adjustments
;	10-25-88  JCR	General cleanup for 386-only code
;	03-23-90  GJF	Changed to _stdcall. Also, fixed the copyright.
;	01-17-91  GJF	ANSI naming.
;	05-10-91  GJF	Back to _cdecl, sigh...
;	10-27-92  SKS	Avoid using a MASM keyword ("C") as a parameter name
;
;*******************************************************************************

	.xlist
	include cruntime.inc
	.list

page
;***
;char *_memccpy(dest, src, _c, count) - copy bytes until character found
;
;Purpose:
;	Copies bytes from src to dest until count bytes have been
;	copied, or up to and including the character _c, whichever
;	comes first.
;
;	Algorithm:
;	char *
;	_memccpy (dest, sorc, _c, count)
;	      char *dest, *sorc, _c;
;	      unsigned int count;
;	      {
;	      while (count && (*dest++ = *sorc++) != _c)
;		      count--;
;
;	      return(count ? dest : NULL);
;	      }
;
;Entry:
;	char *dest - pointer to memory to receive copy
;	char *src - source of bytes
;	char _c - character to stop copy at
;	int count - max number of bytes to copy
;
;Exit:
;	returns pointer to byte immediately after _c in dest;
;	returns NULL if _c was never found
;
;Uses:
;
;Exceptions:
;
;*******************************************************************************

	CODESEG

	public	_memccpy
_memccpy proc \
	uses edi esi, \
	dest:ptr byte, \
	sorc:ptr byte, \
	_c:byte, \
	count:IWORD

	mov	edi,dest	; di = dest
	mov	esi,sorc	; si = source

	mov	ah,_c		; ah = byte to look for
	mov	ecx,count	; cx = max byte count
	jecxz	short retnull	; don't do loop if nothing to move

lupe:
	lodsb			; get byte into al and kick si
	stosb			; store byte from al and kick di
	cmp	al,ah		; see if we just moved the byte
	je	short toend	; end of string

	loop	lupe		; dec cx & jmp to lupe if nonzero
				; else drop out & return NULL
retnull:
	xor	edi,edi 	; null pointer
toend:
	mov	eax,edi 	; return value

ifdef	_STDCALL_
	ret	2*DPSIZE + 2*ISIZE ; _stdcall return
else
	ret			; _cdecl return
endif

_memccpy endp
	end