Rev 1408 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1408 | Rev 1627 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | # strncmp() Author: Kees J. Bot 1 Jan 1994 |
1 | /* strncmp() Author: Kees J. Bot */ |
- | 2 | /* 1 Jan 1994 */ |
|
Line 2... | Line 3... | ||
2 | 3 | ||
3 | # int strncmp(const char *s1, const char *s2, size_t ecx) |
4 | /* int strncmp(const char *s1, const char *s2, size_t ecx) */ |
4 | # Compare two strings. |
5 | /* Compare two strings. */ |
5 | # |
- | |
6 | 6 | /* */ |
|
7 | .intel_syntax |
7 | #include "asm.h" |
8 | 8 | ||
9 | .globl __strncmp |
- | |
10 | - | ||
11 | .text |
- | |
12 | .align 16 |
9 | ENTRY(_strncmp) |
13 | __strncmp: |
- | |
14 | push ebp |
10 | push %ebp |
15 | mov ebp, esp |
- | |
16 | 11 | movl %esp, %ebp |
|
17 | push esi |
12 | push %esi |
18 | push edi |
- | |
19 | 13 | push %edi |
|
20 | test ecx, ecx # Max length is zero? |
14 | testl %ecx, %ecx /* Max length is zero? */ |
21 | je done |
- | |
22 | 15 | je done |
|
23 | mov esi, [ebp+8] # esi = string s1 |
16 | movl 8(%ebp), %esi /* esi = string s1 */ |
24 | mov edi, [ebp+12] # edi = string s2 |
17 | movl 12(%ebp), %edi /* edi = string s2 */ |
25 | cld |
18 | cld |
26 | compare: |
19 | compare: |
27 | cmpsb # Compare two bytes |
20 | cmpsb /* Compare two bytes */ |
28 | jne done |
- | |
29 | 21 | jne done |
|
30 | cmpb [esi-1], 0 # End of string? |
22 | cmpb $0, -1(%esi) /* End of string? */ |
31 | je done |
- | |
32 | 23 | je done |
|
33 | dec ecx # Length limit reached? |
24 | decl %ecx /* Length limit reached? */ |
34 | jne compare |
25 | jne compare |
35 | done: |
26 | done: |
36 | seta al # al = (s1 > s2) |
27 | seta %al /* al = (s1 > s2) */ |
37 | setb ah # ah = (s1 < s2) |
28 | setb %ah /* ah = (s1 < s2) */ |
38 | subb al, ah |
29 | subb %ah, %al |
39 | movsx eax, al # eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1 |
- | |
40 | 30 | movsbl %al, %eax /* eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1 */ |
|
41 | pop edi |
31 | pop %edi |
42 | pop esi |
32 | pop %esi |
43 | pop ebp |
33 | pop %ebp |