|
|
1.1 ! root 1: .file "strcmp.s" ! 2: # @(#)strcmp.s 1.4 ! 3: # Fast assembler language version of the following C-program for ! 4: # strcmp ! 5: # which represents the `standard' for the C-library. ! 6: ! 7: # strcmp(s1, s2) ! 8: # register char *s1, *s2; ! 9: # { ! 10: # if(s1 == s2) ! 11: # return(0); ! 12: # while(*s1 == *s2++) ! 13: # if(*s1++ == '\0') ! 14: # return(0); ! 15: # return(*s1 - *--s2); ! 16: # } ! 17: .globl _strcmp ! 18: .text ! 19: .align 2 ! 20: _strcmp: ! 21: .word 0x0000 # uses regs. 0,1,2,3,4 ! 22: movq 4(ap),r3 # s1 in r3; s2 in r4 ! 23: cmpl r3,r4 # if pointers are eql, don't bother ! 24: bneq L0 ! 25: clrl r0 ! 26: ret ! 27: L0: ! 28: locc $0,$65535,(r4) # search for a terminating null in s2 ! 29: bneq L1 # found a null, go start comparison ! 30: cmpc3 $65535,(r4),(r3) ! 31: bneq L2 # no null in s2, but strings differ ! 32: movl r1,r4 # hey, first BLOCK of chars are same. ! 33: jmp L0 # let's go continue this loop. ! 34: L1: ! 35: subl2 r4,r1 # length of (final segment) of s2 in r1 ! 36: incl r1 # gotta include null in comparison ! 37: cmpc3 r1,(r4),(r3) # strings compared. ! 38: beql L3 # complete equality - r0 is already 0 ! 39: L2: ! 40: cvtbl (r3),r0 ! 41: cvtbl (r1),r1 ! 42: subl2 r1,r0 ! 43: L3: ! 44: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.