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

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. ; strcmpl- Compares the string pointed at by es:si to the string following
  6. ;       the call instruction.
  7. ;
  8. ; inputs:
  9. ;
  10. ;    es:di-    First string (The string to compare)
  11. ;    cs:rtn-    Second string (The string to compare against)
  12. ;
  13. ;    e.g.,
  14. ;        "if (es:si < cs:rtn) 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_strcmpl
  25. ;
  26. sl_strcmpl    proc    far
  27.         push    bp
  28.         mov    bp, sp
  29.         push    es
  30.         push    ds
  31.         push    cx
  32.         push    si
  33.         push    di
  34.         mov    ax, es
  35.         mov    ds, ax
  36.         mov    si, di
  37.         les    di, 2[bp]
  38. ;
  39. ; In order to preserve the direction flag across this call, we have to
  40. ; test whether or not it is set here and execute two completely separate
  41. ; pieces of code (so we know which state to exit in.  Unfortunately, we
  42. ; cannot use pushf to preserve this flag since we need to return status
  43. ; info in the other flags.
  44. ;
  45.         pushf
  46.         pop    ax
  47.         test    ah, 4        ;Test direction bit.
  48.         jnz    DirIsSet
  49. ;
  50. ; Compute the length of the string following the CALL instruction:
  51. ;
  52.         cld
  53.         mov    al, 0
  54.         mov    cx, 0ffffh
  55.     repne    scasb
  56.         xchg    di, 2[bp]    ;Save as new return address.
  57.         neg    cx
  58.         dec    cx        ;Length of string.
  59.         mov    ax, cx
  60.         repe    cmpsb            ;Compare the two strings.
  61. ;
  62.         pushf
  63.         sub    ax, cx
  64.         dec    ax
  65.                 popf
  66.         pop    di
  67.         pop    si
  68.         pop    cx
  69.         pop    ds
  70.         pop    es
  71.         pop    bp
  72.         ret            ;Return with direction flag clear.
  73. ;
  74. ;
  75. DirIsSet:    cld
  76.         mov    al, 0
  77.         mov    cx, 0ffffh
  78.     repne    scasb
  79.         xchg    di, 2[bp]    ;Save as new return address.
  80.         neg    cx
  81.         dec    cx        ;Length of string.
  82.         mov    ax, cx
  83.         repe    cmpsb            ;Compare the two strings.
  84. ;
  85.         pushf
  86.         sub    ax, cx
  87.         dec    ax
  88.         popf
  89.         pop    di
  90.         pop    si
  91.         pop    cx
  92.         pop    ds
  93.         pop    es
  94.         pop    bp
  95.         std
  96.         ret            ;Return with direction flag set.
  97. ;
  98. ;
  99. ;
  100. sl_strcmpl    endp
  101. ;
  102. ;
  103. stdlib        ends
  104.         end
  105.