UbixOS V2 2.0

strncmp.S
Go to the documentation of this file.
1 /*-
2 * Copyright (c) 2002-2018 The UbixOS Project.
3 * All rights reserved.
4 *
5 * This was developed by Christopher W. Olsen for the UbixOS Project.
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright notice, this list of
11 * conditions, the following disclaimer and the list of authors.
12 * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions, the following disclaimer and the list of authors in the documentation and/or
14 * other materials provided with the distribution.
15 * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <i386/asmacros.h>
30
31 ENTRY(strncmp)
32 pushl %ebx
33 movl 8(%esp),%eax
34 movl 12(%esp),%ecx
35 movl 16(%esp),%edx
36 testl %edx,%edx
37 jmp L2 /* Jump into the loop! */
38
39 .align 2,0x90
40 L1: incl %eax
41 incl %ecx
42 decl %edx
43 L2: jz L4 /* strings are equal */
44 movb (%eax),%bl
45 testb %bl,%bl
46 jz L3
47 cmpb %bl,(%ecx)
48 jne L3
49 incl %eax
50 incl %ecx
51 decl %edx
52 jz L4
53 movb (%eax),%bl
54 testb %bl,%bl
55 jz L3
56 cmpb %bl,(%ecx)
57 jne L3
58
59 incl %eax
60 incl %ecx
61 decl %edx
62 jz L4
63 movb (%eax),%bl
64 testb %bl,%bl
65 jz L3
66 cmpb %bl,(%ecx)
67 jne L3
68
69 incl %eax
70 incl %ecx
71 decl %edx
72 jz L4
73 movb (%eax),%bl
74 testb %bl,%bl
75 jz L3
76 cmpb %bl,(%ecx)
77 jne L3
78
79 incl %eax
80 incl %ecx
81 decl %edx
82 jz L4
83 movb (%eax),%bl
84 testb %bl,%bl
85 jz L3
86 cmpb %bl,(%ecx)
87 jne L3
88
89 incl %eax
90 incl %ecx
91 decl %edx
92 jz L4
93 movb (%eax),%bl
94 testb %bl,%bl
95 jz L3
96 cmpb %bl,(%ecx)
97 jne L3
98
99 incl %eax
100 incl %ecx
101 decl %edx
102 jz L4
103 movb (%eax),%bl
104 testb %bl,%bl
105 jz L3
106 cmpb %bl,(%ecx)
107 jne L3
108
109 incl %eax
110 incl %ecx
111 decl %edx
112 jz L4
113 movb (%eax),%bl
114 testb %bl,%bl
115 jz L3
116 cmpb %bl,(%ecx)
117 je L1
118
119 .align 2,0x90
120 L3: movzbl (%eax),%eax /* unsigned comparison */
121 movzbl (%ecx),%ecx
122 subl %ecx,%eax
123 popl %ebx
124 ret
125 .align 2,0x90
126 L4: xorl %eax,%eax
127 popl %ebx
128 ret
129 END(strncmp)