1/* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific written prior permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13#if defined(SYSLIBC_SCCS) && !defined(lint) 14_sccsid:.asciz "@(#)strncmp.s 5.4 (Berkeley) 05/25/88" 15#endif /* SYSLIBC_SCCS and not lint */ 16 17/* 18 * Compare at most n characters of string 19 * s1 lexicographically to string s2. 20 * Return: 21 * 0 s1 == s2 22 * > 0 s1 > s2 23 * < 0 s2 < s2 24 * 25 * strncmp(s1, s2, n) 26 * char *s1, *s2; 27 * int n; 28 */ 29#include "DEFS.h" 30 31ENTRY(strncmp, 0) 32 movl 4(ap),r1 # r1 = s1 33 movq 8(ap),r3 # r3 = s2; r4 = n 341: 35 clrl r5 # calculate min bytes to next page boundry 36 subb3 r1,$255,r5 # r5 = (bytes - 1) to end of page for s1 37 subb3 r3,$255,r0 # r0 = (bytes - 1) to end of page for s2 38 cmpb r0,r5 # r5 = min(r0, r5); 39 bgtru 2f 40 movb r0,r5 412: 42 incl r5 # r5 = min bytes to next page boundry 43 cmpl r4,r5 # r5 = min(n, r5); 44 bgeq 3f 45 movl r4,r5 463: 47 cmpc3 r5,(r1),(r3) # compare strings 48 bneq 4f 49 subl2 r5,r4 # check for end of comparison 50 beql 5f 51 subl2 r5,r1 # check if found null yet 52 locc $0,r5,(r1) 53 beql 1b # not yet done, continue checking 54 subl2 r0,r3 55 mnegb (r3),r0 # r0 = '\0' - *s2 56 cvtbl r0,r0 57 ret 584: 59 subl2 r0,r5 # check for null in matching string 60 subl2 r5,r1 61 locc $0,r5,(r1) 62 bneq 5f 63 subb3 (r3),(r1),r0 # r0 = *s1 - *s2 64 cvtbl r0,r0 65 ret 665: 67 clrl r0 # both the same to null 68 ret 69