...nach einem Teilstring suchen mit Instring + InstringReverse(Assembler)?
Autor: Vanja Fuckar
function InString(StartPosition: Cardinal; const Source, Pattern: string): Cardinal; stdcall;
asm
push esi
push edi
push ebx
test StartPosition,-1
je @fw
inc StartPosition
@fw:
mov edi,dword ptr [Source]
mov esi,dword ptr [Pattern]
mov edx,dword ptr [edi-4]
mov ebx,dword ptr [esi-4]
lea edx, [edx+edi] //max source pointer
lea ebx, [ebx+esi] //max pattern pointer
dec edx
dec ebx
add edi,StartPosition
dec edi
mov eax,edi
add eax,dword ptr [esi-4]
dec eax
cmp eax,edx
ja @Er
@1:
mov esi,dword ptr [Pattern]
@2:
movzx ecx,byte ptr [edi]
movzx eax,byte ptr [esi]
or ecx,32
or eax,32
sub ecx,eax
jz @Prov
@ProvKraj:
inc edi
cmp edi,edx
ja @Er //kraj stringa
jmp @1 //ponovo nije isto slovo...
@Prov:
cmp esi,ebx
jne @Nije
//String odgovara!
sub ebx,dword ptr [Pattern]
sub edi,ebx
sub edi,dword ptr [Source]
mov eax,edi
inc eax //vrati poziciju!
pop ebx
pop edi
pop esi
pop ebp
ret 12
@Nije:
inc edi
inc esi
cmp edi,edx
jbe @2
@Er:
xor eax,eax
pop ebx
pop edi
pop esi
pop ebp
ret 12
end;
function InStringReverse(StartPosition: Cardinal; const Source, Pattern: string): Cardinal;
stdcall;
asm
push esi
push edi
push ebx
mov edx,dword ptr [Source] //max source pointer
mov ebx,dword ptr [Pattern] //max pattern pointer
mov edi,dword ptr [edx-4]
mov esi,dword ptr [ebx-4]
// izraèunaj zadnji moguæi karakter
test StartPosition,-1
jne @fw
mov eax,edi
sub eax,esi
inc eax
mov StartPosition,eax
@fw:
lea esi, [ebx+esi]
dec esi
mov edi,edx
add edi,StartPosition
add edi,dword ptr [ebx-4]
lea edi, [edi-2]
//provjeri dali je izvan stringa!
mov ecx,edx
add ecx,dword ptr [edx-4]
dec ecx
cmp edi,ecx
ja @Er
////////////////////////////////
@1:
mov esi,dword ptr [Pattern]
add esi,dword ptr [esi-4]
dec esi
@2:
movzx ecx,byte ptr [edi]
movzx eax,byte ptr [esi]
or ecx,32
or eax,32
sub ecx,eax
jz @Prov
@ProvKraj:
dec edi
cmp edi,edx
jb @Er //kraj stringa
jmp @1 //ponovo nije isto slovo...
@Prov:
cmp esi,ebx
jne @Nije
//String odgovara!
sub edi,dword ptr [Source]
mov eax,edi
inc eax //vrati poziciju!
pop ebx
pop edi
pop esi
pop ebp
ret 12
@Nije:
dec edi
dec esi
cmp edi,edx
jae @2
@Er:
xor eax,eax
pop ebx
pop edi
pop esi
pop ebp
ret 12
end;
printed from
www.swissdelphicenter.ch
developers knowledge base