home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRICMPL.ASM < prev    next >
Assembly Source File  |  1990-05-31  |  3KB  |  128 lines

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