File:  [MW Coherent from dump] / coherent / b / lib / libc / string / i8086 / memchr.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

//////////
/ i8086 C string library.
/ memchr()
/ ANSI 4.11.5.1.
//////////

//////////
/ char *
/ memchr(String, Char, Count)
/ char *String;
/ int Char, Count;
/
/ Find Char in String, return pointer or NULL.
//////////

#include <larges.h>

String	=	LEFTARG
Char	=	String+DPL
Count	=	Char+2

	Enter(memchr_)
	mov	cx, Count(bp)	/ Count to CX
	or	cx, cx
	je	1f		/ No match possible in first 0 characters
	Les	di, String(bp)	/ String address to ES:SI
	movb	al, Char(bp)	/ Char to AL
	cld
	repne
	scasb			/ Look for character
	je	2f		/ Matched

1:	sub	ax, ax		/ No match, return NULL
#if	LARGEDATA
	mov	dx, ax
#endif
	jmp	3f

2:	dec	di		/ Back up to match
	mov	ax, di		/ AX = offset
#if	LARGEDATA
	mov	dx, es		/ DX = segment
#endif

3:	Leave

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.