1/* 2 * (c) Copyright 1986 HEWLETT-PACKARD COMPANY 3 * 4 * To anyone who acknowledges that this file is provided "AS IS" 5 * without any express or implied warranty: 6 * permission to use, copy, modify, and distribute this file 7 * for any purpose is hereby granted without fee, provided that 8 * the above copyright notice and this notice appears in all 9 * copies, and that the name of Hewlett-Packard Company not be 10 * used in advertising or publicity pertaining to distribution 11 * of the software without specific, written prior permission. 12 * Hewlett-Packard Company makes no representations about the 13 * suitability of this software for any purpose. 14 */ 15 16/* SPECTRUM_ID: @(#)memchr.s 37.4 86/04/23 */ 17/* 18 * memchr(s, c, n) 19 * 20 * returns pointer to first occurrence of char c 21 * in first n characters of memory area s, 22 * or null if c does not occur. 23 */ 24 25#include "DEFS.h" 26 27#define FROM arg0 28#define CHAR arg1 29#define COUNT arg2 30#define TEMP1 r19 31 32ENTRY(memchr) 33 comb,<= COUNT,r0,memchrexit /* return if count is zero */ 34 copy r0,ret0 /* null if c not found in n chars */ 35 depi 0,23,24,CHAR /* make char unsigned */ 36 37 ldbs,ma 1(FROM),TEMP1 38memchrloop: 39 comb,=,n TEMP1,CHAR,memchrequal 40 addib,<> -1,COUNT,memchrloop 41 ldbs,ma 1(FROM),TEMP1 42 b,n memchrexit 43 44memchrequal: 45 ldo -1(FROM),ret0 46 47memchrexit: 48EXIT(memchr) 49