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,752 of 4,675    |
|    Terje Mathisen to wolfgang kern    |
|    Re: another stricmp()    |
|    28 Jun 17 15:32:04    |
   
   From: terje.mathisen@nospicedham.tmsw.no   
      
   wolfgang kern wrote:   
   > Yes Ben,   
   >   
   > even not too fast.. this looks much better yet! :)   
   > __   
   > wolfgang   
   >> ; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-   
   >> ; this routine compares (case insensitive) two strings   
   >> ; ds:si->string0 (asciiz)   
   >> ; es:di->string1 (asciiz)   
   >> ; returns zero flag set if equal   
   >> ; carry flag set if string0 < string1   
   >> ; carry flag clear if string0 > string1   
   >> ; preserves: si, di   
   >> ; destroys: ax   
   >> stricmp proc near uses si di   
   >>   
   >> @@: mov al,es:[di]   
   >> inc di   
   >> call upper_case   
   >> mov ah,al   
   >>   
   >> lodsb   
   >> call upper_case   
   >>   
   >> ; if both strings are equal and we are at   
   >> ; the null terminator, we need to exit now   
   >> or ax,ax   
   >> jz short @f   
   >>   
   >> ; 'sub' will set/clr the zero flag   
   >> ; and the carry flag for us   
   >> sub al,ah   
   >> jz short @b   
   >>   
   >> @@: ret   
   >> stricmp endp   
   >>   
   >> upper_case proc near   
   >> cmp al,'a'   
   >> jb short @f   
   >> cmp al,'z'   
   >> ja short @f   
   >> sub al,('a'-'A')   
   >> @@: ret   
   >> upper_case endp   
   >>   
   >> .end   
      
   This looks extremely "by the book", i.e. straight forward coding.   
      
   You could combine a few of the current ideas:   
      
   next:   
    lodsb   
    test al,al   
    scasb   
    jz check_end   
      
   Is this a case mismatch?   
    xor al,32   
    cmp al,es:[di-1]   
    jnz done   
      
   Was it an a-z char?   
    or al,32   
    sub al,'a'   
    jb done   
    cmp al,'z'   
    ja done   
    jmp next   
      
   check_end:   
   All chars up to here have matched   
    test al,al   
    jnz next   
   done:   
    ret   
      
   Setting the proper return codes is left as an exercise. :-)   
      
   Terje   
      
   --   
   -
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca