Rev 1467 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1467 | Rev 3244 | ||
---|---|---|---|
1 | ; strlen function |
1 | ; strlen function |
2 | ; |
2 | ; |
3 | ; Copyright (c) 2003 Thomas Mathys |
3 | ; Copyright (c) 2003 Thomas Mathys |
4 | ; killer@vantage.ch |
4 | ; killer@vantage.ch |
5 | ; |
5 | ; |
6 | ; This program is free software; you can redistribute it and/or modify |
6 | ; This program is free software; you can redistribute it and/or modify |
7 | ; it under the terms of the GNU General Public License as published by |
7 | ; it under the terms of the GNU General Public License as published by |
8 | ; the Free Software Foundation; either version 2 of the License, or |
8 | ; the Free Software Foundation; either version 2 of the License, or |
9 | ; (at your option) any later version. |
9 | ; (at your option) any later version. |
10 | ; |
10 | ; |
11 | ; This program is distributed in the hope that it will be useful, |
11 | ; This program is distributed in the hope that it will be useful, |
12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | ; GNU General Public License for more details. |
14 | ; GNU General Public License for more details. |
15 | ; |
15 | ; |
16 | ; You should have received a copy of the GNU General Public License |
16 | ; You should have received a copy of the GNU General Public License |
17 | ; along with this program; if not, write to the Free Software |
17 | ; along with this program; if not, write to the Free Software |
18 | ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | ; |
19 | ; |
20 | ;%ifndef _STRLEN_INC |
20 | ;%ifndef _STRLEN_INC |
21 | ;%define _STRLEN_INC |
21 | ;%define _STRLEN_INC |
22 | 22 | ||
23 | 23 | ||
24 | ;******************************************************************** |
24 | ;******************************************************************** |
25 | ; returns the length of an asciiz string |
25 | ; returns the length of an asciiz string |
26 | ; input : esi = pointer to string |
26 | ; input : esi = pointer to string |
27 | ; output : eax = string length |
27 | ; output : eax = string length |
28 | ; destroys : nothing |
28 | ; destroys : nothing |
29 | ;******************************************************************** |
29 | ;******************************************************************** |
30 | strlen: |
30 | strlen: |
31 | push ecx edi |
31 | push ecx edi |
32 | pushfd |
32 | pushfd |
33 | cld ; ! |
33 | cld ; ! |
34 | mov ecx,-1 |
34 | mov ecx,-1 |
35 | mov edi,esi ; find terminating zero |
35 | mov edi,esi ; find terminating zero |
36 | xor al,al |
36 | xor al,al |
37 | repne scasb |
37 | repne scasb |
38 | mov eax,edi ; calculate string length |
38 | mov eax,edi ; calculate string length |
39 | sub eax,esi |
39 | sub eax,esi |
40 | dec eax |
40 | dec eax |
41 | popfd |
41 | popfd |
42 | pop edi ecx |
42 | pop edi ecx |
43 | ret |
43 | ret |
44 | 44 | ||
45 | 45 | ||
46 | 46 | ||
47 | ; linlen function |
47 | ; linlen function |
48 | ; |
48 | ; |
49 | ; Copyright (c) 2009 Igor Afanasiev |
49 | ; Copyright (c) 2009 Igor Afanasiev |
50 | 50 | ||
51 | linlen: |
51 | linlen: |
52 | push ecx edi |
52 | push ecx edi |
53 | pushfd |
53 | pushfd |
54 | cld ; ! |
54 | cld |
55 | mov ecx,eax |
55 | mov ecx,eax |
56 | inc ecx |
56 | inc ecx |
57 | mov edi,esi ; find terminating zero |
57 | mov edi,esi ; find terminating zero |
58 | mov al,13 |
58 | mov al,13 |
59 | repne scasb |
59 | repne scasb |
60 | mov eax,edi ; calculate string length |
60 | mov eax,edi ; calculate string length |
61 | sub eax,esi |
61 | sub eax,esi |
62 | dec eax |
62 | dec eax |
63 | popfd |
63 | popfd |
64 | pop edi ecx |
64 | pop edi ecx |
65 | ret |
65 | ret |
- | 66 | ||
- | 67 | ;description: |
|
- | 68 | ; проверяет содержится ли строка str1 в строке str0 |
|
- | 69 | ; проверка делается только начиная с первых символов, указанных в str0 и str1 |
|
- | 70 | ; пример 1: если str0='aaabbbccc', str1='bbb' совпадения не будет |
|
- | 71 | ; пример 2: если str0='aaabbbccc', str1='aaa' совпадение будет |
|
- | 72 | ;output: |
|
- | 73 | ; al = 0 если строка str1 содержится в str0 |
|
- | 74 | ; al != 0 если строка str1 не содержится в str0 |
|
- | 75 | align 4 |
|
- | 76 | proc str_instr uses edi esi, str0:dword, str1:dword |
|
- | 77 | ;xor eax,eax |
|
- | 78 | mov edi,[str0] |
|
- | 79 | mov esi,[str1] |
|
- | 80 | cld |
|
- | 81 | @@: |
|
- | 82 | mov al,[esi] |
|
- | 83 | cmp al,0 |
|
- | 84 | je .e1 |
|
- | 85 | inc esi |
|
- | 86 | scasb ;сравниваем символы |
|
- | 87 | jz @b ;если совпали, то переходим к сравнению следующих |
|
- | 88 | ;сюда попадаем если строки не совпали |
|
- | 89 | sub al,[edi-1] |
|
- | 90 | .e1: ;сюда попадаем если строка str1 (esi) закончилась |
|
- | 91 | ret |
|
66 | ;%endif |
92 | endp |