Another PosEx Entry

From: Eric W. Carman (ewcarman_at_)
Date: 03/17/05

Date: Thu, 17 Mar 2005 08:19:08 -0500

Hello All,

This is my contribution to the efforts. Not the fastest to be sure, but not
the slowest either....

Also, in the B&V tool I noticed the following:

- The text for validate 1 reads "Running Validate 16"
- Can we add a generic PosEx to the Main Unit with IFDEFs to allow it to
compile for D6. D6 doesn't have one of its own.

Here it is:

function PosEx_EWC_IA32(const SubStr, S: string; Offset: Integer = 1):
//Pattern = edi
//Source = esi
//SourceOffset/LoopVar = ecx
//PatternLength = edx
//Result = eax
  test eax, eax
  jz @NotFound

  test edx, edx
  jz @NotFound

  cmp ecx, 0
  jle @NotFound

  push esi
  push edi
  mov edi,eax

  sub ecx, 1 //Make Offset relative to zero
  lea esi,[edx+ecx] //Load esi with starting addr of source string

  mov eax,[edx-$04] //Get String Source Length
  push eax
  mov edx,[edi-$04] //Get String Pattern Length

  test eax, eax
  jz @NotFoundPop
  test edx, edx
  jz @NotFoundPop

                      //Calculate Number of Loops to execute
  sub eax,ecx // Subtract the Offset from the Length of the String
  sub eax,edx // Backoff the Length of the Pattern
  lea ecx,[eax+1] // Add 1 and move the result to the LoopVar

  test ecx,ecx //If Pattern is longer than the remaining Source
  jle @NotFoundPop // Pattern was not found.
  jmp @BeginLoop

  lea esi, [esi+1] //Advance to next Source character

  mov al,[edi] //Get Pattern Character
  cmp al,[esi] //Compare to Source Character
  jnz @NextSource //If no match, break loop

  push edx //Save Pattern Length

  sub edx, 1 //Make Pattern Count an Offset/Dec Loop Counter
  jle @Found //If end of Pattern then must be found
  mov al, [edi+edx] //Get Pattern Char
  cmp al, [esi+edx] //Compare to Source Char
  je @PatternLoop //if Pattern Char Matches

  pop edx //Restore Pattern Count if not found

  sub ecx, 1
  jnz @NextSourceChar

  pop eax
  pop edi
  pop esi
  xor eax, eax
  jmp @Done

  pop edx
  pop eax //Length of Source String
  pop edi
  pop esi

  sub eax, ecx //Subtract Number of Iterations Left
  sub eax, edx //Add the Length of the Pattern
  lea eax,[eax+2]



Relevant Pages