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,760 of 4,675   
   Kerr Mudd-John to wolfgang kern   
   Re: another stricmp()   
   29 Jun 17 15:36:17   
   
   From: admin@nospicedham.127.0.0.1   
      
   On Wed, 28 Jun 2017 10:33:59 +0100, 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   
      
   This would be quicker if the strings are expected to be same case and matching:   
   (Assuming I've not made any erorrs! - untested:)   
      
   but then again a repnz cmpsb would get to the first (possible) mismatch with   
   less code quicker.   
      
   stricmp:     ; uses al   
                 dec di           ; to start   
   nextcmp:   
                 lodsb   
                 cmp al,0   
                 jz  endstr0   
                 inc di   
                 or  al,es:[di]   
                 jz  nextcmp      ; equal so far   
                 cmp al,0x20   
                 jne isdifferent  ; too different   
                 ; might be just case   
                 or al,[si-1]   
                 cmp al,'a'   
                 jg isdifferent   
                 cmp al,'a'   
                 jg nextcmp       ; alpha ok   
      
   isdifferent: mov al,es:[di]   
                 sub al,[si-1]    ; for cy flag   
   issame:      ret   
      
   endstr0:     cmp es:[di+1],0   
                 jz  issame   
                 jnz isdifferent   
      
      
      
      
   >> @@:        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   
   >   
      
      
   --   
   Bah, and indeed, Humbug   
      
   --- 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