|
|
1.1 root 1: .file "memcmp.s"
2: # @(#)memcmp.s 1.5
3: # Fast assembler language version of the following C-program for
4: # memcmp
5: # which represents the `standard' for the C-library.
6:
7: # Compare n bytes: s1>s2: >0 s1==s2: 0 s1<s2: <0
8:
9: # int
10: # memcmp(s1, s2, n)
11: # register char *s1, *s2;
12: # register int n;
13: # {
14: # int diff;
15: #
16: # if (s1 != s2)
17: # while (--n >= 0)
18: # if (diff = *s1++ - *s2++)
19: # return (diff);
20: # return (0);
21: # }
22: .globl _memcmp
23: .text
24: .align 2
25: _memcmp:
26: .word 0x0000 # uses regs. 0,1,2,3,4
27: movl 12(ap),r4 # arg `n'
28: bleq L4 # should be > 0
29: movq 4(ap),r1 # s1 in r1; s2 in r2
30: cmpl r1,r2 # if pointers are eql, strings are also
31: beql L4 # return a zero
32: movl r2,r3 # s2
33: L0:
34: cmpl $65535,r4 # check for whether `n' <= 65535
35: bgeq L1 # skip if r4 is not too big
36: cmpc3 $65535,(r1),(r3) # Compare s1 and s2
37: bneq L2 # skip if strings are !=
38: subl2 $65535,r4
39: jbr L0 # more compare is needed, go back
40: L1:
41: cmpc3 r4,(r1),(r3) # Compare s1 and s2
42: beql L3 # skip if strings are ==
43: L2:
44: subb3 (r3),(r1),r0 # difference is returned
45: cvtbl r0,r0 # gotta make it an int
46: L3:
47: ret # else return a zero (r0 = 0 already)
48: L4:
49: clrl r0 # n <= 0; return a zero
50: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.