1: /*
   2:  * Copyright (c) 1987 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:         <@(#)strncmp.s	1.1 (Berkeley) 1/21/87\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: /*
  13:  * Compare at most n characters of string
  14:  * s1 lexicographically to string s2.
  15:  * Return:
  16:  *	0	s1 == s2
  17:  *	> 0	s1 > s2
  18:  *	< 0	s2 < s2
  19:  *
  20:  * strncmp(s1, s2, n)
  21:  *	char *s1, *s2;
  22:  *	int n;
  23:  */
  24: #include "DEFS.h"
  25: 
  26: ENTRY(strncmp)
  27:         mov     6(sp),r0        / r0 = n
  28:         beq     4f              / (all done if n == 0 - return 0)
  29:         mov     2(sp),r1        / r1 = s1
  30:         mov     r2,-(sp)        / need an extra register for s2 ...
  31:         mov     6(sp),r2        / r2 = s2
  32: 1:
  33:         cmpb    (r1)+,(r2)      / compare the two strings
  34:         bne     5f              / stop on first mismatch
  35:         tstb    (r2)+           / but don't pass end of either string
  36:         beq     2f
  37:         sob     r0,1b           / and n running out will stop us too ...
  38: 2:
  39:         clr     r0              / fell off end of strings while still matching
  40: 3:
  41:         mov     (sp)+,r2        / restore r2
  42: 4:
  43:         rts     pc              / and return
  44: 5:
  45:         movb    -(r1),r0        / mismatch, return *s1 - *s2 ...
  46:         movb    (r2),r1         / (no subb instruction ...)
  47:         sub     r1,r0
  48:         br      3b

Defined functions

_strncmp defined in line 26; used 504 times
Last modified: 1987-01-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3807
Valid CSS Valid XHTML 1.0 Strict