home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,729 of 4,675   
   James Harris to All   
   Re: Optimize stricmp() algorithm (casele   
   27 Jun 17 10:29:41   
   
   From: james.harris.1@nospicedham.gmail.com   
      
   On 27/06/2017 09:51, James Harris wrote:   
      
   Here's an effort at the code needed. All untested. The inner loop is a   
   seven-instruction scan for either (1) the end of the first string or (2)   
   two bytes (one from each string) which are not identical.   
      
   ASCII case-insensitive string comparison   
   Register usage   
   ESI: pointer to start of string 0   
   EDI: pointer to start of string 1   
   EBX: offset from the start of the strings   
   ECX: the current character from string 0   
   EDX: temporary storage   
      
      push ebp   
      mov ebp, esp   
      mov esi, [ebp + 8]      ;Point ESI at start of string 0   
      mov edi, [ebp + 12]     ;Point EDI at start of string 1   
      
      xor ebx, ebx            ;Offset = zero   
      jmp loop_test           ;Skip ahead to loop test   
      
   loop_top:   
      movsx eax, [edi + ebx]  ;Fetch char from string 1   
      xor eax, ecx            ;Xor char from string 0   
      jne not_identical       ;Jump if not identical but might still match   
      
      ;These two bytes are identical. Go on to the next pair   
      
   next_pos:   
      add ebx, 1              ;Next offset   
      
   loop_test:   
      movsx ecx, [esi + ebx]  ;Char from string 0   
      test ecx, ecx           ;The string terminator?   
      jnz loop_top            ;Jump back up if not end of string   
      
   go_back:   
      movsx eax, [esi + ebx]  ;Get char from string 0   
      movsx ebx, [edi + ebx]  ;Get char from string 1   
      sub eax, ebx            ;Calculate difference   
      pop ebp   
      ret 8   
      
   not_identical:   
      cmp eax, 0x20           ;Could they be the same but different cases?   
      jne go_back             ;Skip if no   
      
      ;The bytes might be different cases of the same letter. Check them   
      push ecx                ;The char from string 0   
      call lower              ;Lower-case it   
      mov edx, eax            ;Save in EDX   
      movsx eax, [edi + ebx]  ;Fetch char from string 1   
      push eax                ;Push it   
      call lower              ;Lower-case it   
      cmp eax, edx            ;Same?   
      je next_pos             ;Yes, continue looping   
      jmp go_back             ;Mismatch found. Go back   
      
      
   --   
   James Harris   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca