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 "@(#)strcmp.s 5.4 (Berkeley) 05/25/88" 15#endif /* SYSLIBC_SCCS and not lint */ 16 17/* 18 * Compare string s1 lexicographically to string s2. 19 * Return: 20 * 0 s1 == s2 21 * > 0 s1 > s2 22 * < 0 s2 < s2 23 * 24 * strcmp(s1, s2) 25 * char *s1, *s2; 26 */ 27#include "DEFS.h" 28 29ENTRY(strcmp, 0) 30 movl 4(ap),r1 # r1 = s1 31 movl 8(ap),r3 # r3 = s2 32 subb3 (r3),(r1),r0 # quick check for first char different 33 beql 1f # have to keep checking 34 cvtbl r0,r0 35 ret 361: 37 clrl r5 # calculate min bytes to next page boundry 38 subb3 r1,$255,r5 # r5 = (bytes - 1) to end of page for s1 39 subb3 r3,$255,r0 # r0 = (bytes - 1) to end of page for s2 40 cmpb r0,r5 # r5 = min(r0, r5); 41 bgtru 2f 42 movb r0,r5 432: 44 incl r5 # r5 = min bytes to next page boundry 45 cmpc3 r5,(r1),(r3) # compare strings 46 bneq 3f 47 subl2 r5,r1 # check if found null yet 48 locc $0,r5,(r1) 49 beql 1b # not yet done, continue checking 50 subl2 r0,r3 51 mnegb (r3),r0 # r0 = '\0' - *s2 52 cvtbl r0,r0 53 ret 543: 55 subl2 r0,r5 # check for null in matching string 56 subl2 r5,r1 57 locc $0,r5,(r1) 58 bneq 4f 59 subb3 (r3),(r1),r0 # r0 = *s1 - *s2 60 cvtbl r0,r0 61 ret 624: 63 clrl r0 # both the same to null 64 ret 65