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

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4.         extrn    sl_malloc:far
  5. ;
  6. ; strdel2- deletes characters from a string.
  7. ;
  8. ; inputs:
  9. ;
  10. ;    ES:DI- Points at the string to delete characters from.
  11. ;
  12. ;    CX-    Index into source string (ES:DI) to begin deletion.
  13. ;
  14. ;    AX-    Number of characters to delete.
  15. ;
  16. ; outputs:
  17. ;
  18. ;    ES:DI-    Points at new string on stack which is the image of the
  19. ;        source string minus the specified characters.
  20. ;
  21. ;    Carry=1 if memory allocation error, 0 if sufficient memory for the
  22. ;        new string.
  23. ;
  24. ;
  25.         public    sl_strdel2
  26. ;
  27. ;
  28. sl_strdel2    proc    far
  29.         push    es
  30.         push    di
  31.         push    si
  32.         push    ds
  33.         push    ax
  34.         push    bx
  35.         push    cx
  36.         mov    bx, ax            ;Save length
  37. ;
  38. ; Compute the length of the source string:
  39. ;
  40.         push    es
  41.         push    di
  42.         push    cx
  43.         mov    cx, 0ffffh
  44.         mov    al, 0
  45.     repne    scasb
  46.         neg    cx
  47.         sub    cx, bx            ;Compute length of new str.
  48.         jnc    DoAlloc            ;Too much to delete?
  49.         pop    cx            ;Use insertion point as
  50.         push    cx            ; the length.
  51. ;
  52. DoAlloc:    call    sl_malloc
  53.         jnc    GoodAlloc
  54.         add    sp, 6
  55.         pop    cx
  56.         pop    bx
  57.         pop    ax
  58.         pop    ds
  59.         pop    si
  60.         pop    di
  61.         pop    es
  62.         ret
  63. ;
  64. GoodAlloc:    pop    cx
  65.         pop    si
  66.         pop    ds
  67.         push    es            ;Save ptr to new string.
  68.         push    di
  69. Cpy1:        lodsb
  70.         stosb
  71.         cmp    al, 0
  72.         loopne    Cpy1
  73.         jz    DelDone
  74. Skp1:        mov    cx, bx            ;Get # chars to delete
  75. Skp2:        lodsb
  76.         cmp    al, 0
  77.         loopne    Skp2
  78.         jz    DelDone
  79. Cpy2:        lodsb
  80.         stosb
  81.         cmp    al, 0
  82.         jnz    Cpy2
  83. ;
  84. DelDone:    mov    byte ptr es:[di], 0
  85.         pop    di
  86.         pop    es
  87.         pop    cx
  88.         pop    bx
  89.         pop    ax
  90.         pop    ds
  91.         pop    si
  92.         add    sp, 4            ;Don't restore es:di
  93.         ret
  94. sl_strdel2    endp
  95. ;
  96. ;
  97. stdlib        ends
  98.         end
  99.