|
|
1.1 root 1: //////////
2: / libc/string/i386/strstr.s
3: / i386 C string library.
4: / ANSI 4.11.5.7.
5: //////////
6:
7: //////////
8: / char *
9: / strstr(char *String1, char *String2)
10: /
11: / Return the first occurance in String1 of String2.
12: / If String2 is empty, return String1.
13: //////////
14:
15: String1 .equ 16
16: String2 .equ String1+4
17:
18: .globl strstr
19:
20: strstr:
21: push %esi
22: push %edi
23: push %ebx
24:
25: movl %ebx, String1(%esp) / String1 address to EBX
26: movl %edi, String2(%esp) / String2 address to EDI
27: movl %edx, %edi / Save String2 start in EDX
28: movl %ecx, $-1 / Max count to ECX
29: subb %al, %al / NUL to AL
30: cld
31: repne
32: scasb / Scan to NUL
33: movl %eax, $-2
34: subl %eax, %ecx / Length of String2 to EAX
35: jz ?gotcha / String2 is empty, just return String1
36:
37: ?loop:
38: movl %ecx, %eax / Count to ECX
39: movl %edi, %edx / String2 address to EDI
40: movl %esi, %ebx / Current location within String1 to ESI
41: repe
42: cmpsb / Compare entire String2 to current String1
43: je ?gotcha / Success, return current location
44: incl %ebx / Mismatched, try next String1 location
45: cmpb -1(%esi), $0 / Check if end of String1 reached
46: jne ?loop / No, keep trying
47: subl %ebx, %ebx / Failure, return NULL
48:
49: ?gotcha:
50: movl %eax, %ebx / Success, return location in String1
51:
52: ?done:
53: pop %ebx
54: pop %edi
55: pop %esi
56: ret
57:
58: / end of libc/string/i386/strstr.s
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.