home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRICMP.ASM < prev    next >
Assembly Source File  |  1990-07-16  |  2KB  |  104 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4.         extrn    $uprtbl:byte
  5. ;
  6. ; stricmp- Compares two strings, ignoring differences in case.
  7. ;
  8. ; inputs:
  9. ;
  10. ;    es:di-    First string (The string to compare)
  11. ;    dx:si-    Second string (The string to compare against)
  12. ;
  13. ;    e.g.,
  14. ;        "if (es:di < dx:si) then ..."
  15. ;
  16. ; returns: 
  17. ;
  18. ;    cx- index into strings where they differ (points at the zero byte
  19. ;        if the two strings are equal).
  20. ;    Condition codes set according to the string comparison.  You should
  21. ;    use the unsigned branches (ja, jb, je, etc.) after calling this
  22. ;    routine.
  23. ;
  24.         public    sl_stricmp
  25. ;
  26. sl_stricmp    proc    far
  27.         push    es
  28.         push    ds
  29.         push    bx
  30.         push    ax
  31.         push    si
  32.         push    di
  33.         xchg    di, si
  34.         mov    ax, es
  35.         mov    ds, ax
  36.         mov    es, dx
  37.         xor    cx, cx        ;Set initial index to zero.
  38.         lea    bx, $uprtbl
  39. ;
  40. ; In order to preserve the direction flag across this call, we have to
  41. ; test whether or not it is set here and execute two completely separate
  42. ; pieces of code (so we know which state to exit in.  Unfortunately, we
  43. ; cannot use pushf to preserve this flag since we need to return status
  44. ; info in the other flags.
  45. ;
  46.         pushf
  47.         pop    ax
  48.         test    ah, 4        ;Test direction bit.
  49.         jnz    DirIsSet
  50. sclp:        lodsb
  51.         xlat    cs:$uprtbl
  52.         mov    ah, al
  53.         mov    al, es:[di]
  54.         xlat    cs:$uprtbl
  55.         cmp    ah, al        
  56.         jne    scNE        ;If strings are <>, quit.
  57.         inc    cx            ;Increment index into strs.
  58.         inc    di        ;Incrment str2 ptr.
  59.         cmp    al, 0        ;Check for end of strings.
  60.         jne    sclp
  61.         pushf
  62.         dec    cx
  63.         popf
  64. ;
  65. scNE:        pop    di
  66.         pop    si
  67.         pop    ax
  68.         pop    bx
  69.         pop    ds
  70.         pop    es
  71.         ret            ;Return with direction flag clear.
  72. ;
  73. ;
  74. DirIsSet:    lodsb
  75.         xlat    cs:$uprtbl
  76.         mov    ah, al
  77.         mov    al, es:[di]
  78.         xlat    cs:$uprtbl        
  79.         cmp    ah, al
  80.         jne    scNE2         ;If strings are <>, quit.
  81.         inc    cx
  82.         inc    di
  83.         cmp    al, 0         ;Check for end of strings.
  84.         jne    DirIsSet
  85.         pushf
  86.         dec    cx
  87.         popf
  88. ;
  89. scNE2:        pop    di
  90.         pop    si
  91.         pop    ax
  92.         pop    bx
  93.         pop    ds
  94.         pop    es
  95.         std            ;Return with direction flag set.
  96.                 ret
  97.  
  98. sl_stricmp    endp
  99. ;
  100. ;
  101. stdlib        ends
  102.         end
  103.