include stdio bool Contains char dataArr char testValue dataArr íóëü ò

 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
#include <stdio.h>
bool Contains(char** dataArr, char* testValue)//dataArr íóëü òåðìèíèðîâàííûé ìàññèâ ASCIIZ ñòðîêâ êîòîðîì âûïîëíÿåòüñÿ ïîèñê, testValue ïðîâåðÿåìàÿ ASCIIZ ñòðîêà
{
bool res;
__asm{
MOV res, 0
CMP dataArr, NULL //åñëè îäèí èç âõîäíûõ ïàðàìåðîâ NULL òî âîçâðàùàåì false
JE End
CMP testValue, NULL
JE End
MOV EAX, dataArr
Foreach :
CMP [EAX], NULL //ýòî ôóíêöèÿ ïðîâåðêè êîíöà ìàññèâà, îí äîëæåí çàêàí÷èâàòüñÿ íöëåâûì óêàçàòåëåì, àëüòåðíàòèâà ïåðåäîâàòü ðàçìåð ìàññèâà â ôóíêöèþ ÿâíî (÷òî íè÷åì íå ëó÷øå).
JE End
//
MOV ESI, [EAX]
MOV EDI, testValue
CmpLoop :
MOV CL, [ESI] //ïîáàéòîâî ñðàâíèâàåì ñèìâîëû â ñòðîêå(ýòî íå ðàáîòàåò äëÿ ìíîãîáàéòîâûõ êîäèðîâîê, íî ðàáîòàåò äëÿ ASCIIZ ñòðîê)
CMP CL, [EDI]
JNE CmpEnd
CMP CL, 0 //ñðàâíèâàåì òåêóùèé ñèìâîë ñ êîäîì êîíöà ñòðîêè(0)
JNE Continue
MOV res, 1 //åñëè îáà óêàçàòåëÿ óêàçûâàþò íà êîíåö ñòðîêè òî ñòðîêè ýêâèâàëåíòíû
JMP End
Continue :
ADD ESI, 1
ADD EDI, 1
JMP CmpLoop
CmpEnd :
ADD EAX, 4 //4 - äëèííà óêàçàòåëÿ â 32-õ áèòíûõ ñèñòåìàõ
JMP Foreach
//
End :
}
return res; //ïðîöåññ âûçîâà è âîçâðàòà èç ôóíêöèè ëó÷øå äîâåðèòü êîìïèëÿòîðó, ÷òîáû íå äóìàòü îá ôîðìèðîâàíèå ñòåêà è ïîëîæåíèè âîçâðàùàåìûõ çíà÷åíèé
}
int main()
{
int aaa = sizeof(char*);
char** dataArr = new char*[]{"A", "ABD", "ABC",NULL};
char* testValue = "A";
bool a = Contains(dataArr, testValue);
bool b = Contains(dataArr, "ABD");
bool c = Contains(dataArr, "ABC");
bool cf = Contains(dataArr, "ABCAA");
bool af = Contains(dataArr, "AB");
bool bf = Contains(dataArr, "ABCAAasdasd");
}