1/* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7#ifdef LIBC_SCCS 8 .asciz "@(#)strncmp.s 5.3 (Berkeley) 03/09/86" 9#endif LIBC_SCCS 10 11/* 12 * Compare at most n characters of string 13 * s1 lexicographically to string s2. 14 * Return: 15 * 0 s1 == s2 16 * > 0 s1 > s2 17 * < 0 s2 < s2 18 * 19 * strncmp(s1, s2, n) 20 * char *s1, *s2; 21 * int n; 22 */ 23#include "DEFS.h" 24 25ENTRY(strncmp, 0) 26 movl 4(ap),r1 # r1 = s1 27 movq 8(ap),r3 # r3 = s2; r4 = n 281: 29 clrl r5 # calculate min bytes to next page boundry 30 subb3 r1,$255,r5 # r5 = (bytes - 1) to end of page for s1 31 subb3 r3,$255,r0 # r0 = (bytes - 1) to end of page for s2 32 cmpb r0,r5 # r5 = min(r0, r5); 33 bgtru 2f 34 movb r0,r5 352: 36 incl r5 # r5 = min bytes to next page boundry 37 cmpl r4,r5 # r5 = min(n, r5); 38 bgeq 3f 39 movl r4,r5 403: 41 cmpc3 r5,(r1),(r3) # compare strings 42 bneq 4f 43 subl2 r5,r4 # check for end of comparison 44 beql 5f 45 subl2 r5,r1 # check if found null yet 46 locc $0,r5,(r1) 47 beql 1b # not yet done, continue checking 48 subl2 r0,r3 49 mnegb (r3),r0 # r0 = '\0' - *s2 50 cvtbl r0,r0 51 ret 524: 53 subl2 r0,r5 # check for null in matching string 54 subl2 r5,r1 55 locc $0,r5,(r1) 56 bneq 5f 57 subb3 (r3),(r1),r0 # r0 = *s1 - *s2 58 cvtbl r0,r0 59 ret 605: 61 clrl r0 # both the same to null 62 ret 63