-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPROC_FindString.asm
67 lines (49 loc) · 1.16 KB
/
PROC_FindString.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
.data
String DB "This is sshort sentence. :D",0Dh,0Ah,0
Searched DB "short",0
.code
Comment /* Returns position of the first found substring in string in EAX. */
FindString PROC USES ebx ecx edx edi esi paOffSourceStr, paOffSearched
mov eax, paOffSourceStr
mov ebx, paOffSearched
mov edi, 0 ;iter of eax (paOffSourceStr)
mov esi, 0 ;iter of ebx (paOffSearched)
mov edx, 0 ;searched position
Search:
mov ch, [ebx + esi] ;set searched char
cmp ch, 0
je Found ;end - found
mov cl, [eax + edi] ;set compared char
cmp cl, 0
je NotFound ;end - did not find
cmp ch, cl ;compare searched and compared char
je CharMatch ;inc esi
cmp esi, 0
je NoDecEdi
dec edi ;return one loop
NoDecEdi:
mov esi, 0
mov edx, edi ;set possibly found position
inc edx ;it will by the next position
RetCharMatch:
inc edi
jmp Search
CharMatch:
inc esi
jmp RetCharMatch
Found:
mov eax, edx
ret
NotFound:
mov eax, -1
ret
FindString ENDP
main PROC
invoke FindString, offset String, offset Searched
call WriteInt
call Crlf
exit
main ENDP
END main