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

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3.         extrn    sl_malloc:far
  4. ;
  5. ;
  6. ; strdupl- Copies string pointed at by cs:rtnadrs to heap and returns a
  7. ;       pointer to this new string in es:di.
  8. ;
  9. ;
  10. ; inputs:
  11. ;        cs:rtn-    Zero-terminated source string.
  12. ; outputs:
  13. ;        es:di-    Points at destination string on heap.
  14. ;
  15. ;
  16. ;
  17.         public    sl_strdupl
  18. ;
  19. rtnadrs        equ       2[bp]
  20. ;
  21. sl_strdupl    proc    far
  22.         push    bp
  23.         mov    bp, sp
  24.         push    ds
  25.         push    cx
  26.         push    ax
  27.         pushf
  28.         push    si
  29. ;
  30.         cld
  31.         mov    al, 0
  32.         mov    cx, 0ffffh
  33.         les    di, rtnadrs
  34.     repne    scasb
  35.         lds    si, rtnadrs
  36.         mov    rtnadrs, di
  37.         neg    cx
  38.         dec    cx
  39. ;
  40. ; Allocate some storage for the string.
  41. ;
  42.         push    cx            ;Save for later
  43.         call    sl_malloc
  44.         pop    cx
  45.         jc    BadStrDupl
  46. ;
  47.         push    es            ;Save ptr to string
  48.         push    di
  49. ;
  50. ; Copy the string to the new space on the heap.
  51. ;
  52.         shr    cx, 1
  53.         jnc    CpyWrd
  54.         lodsb
  55.         stosb
  56. CpyWrd:    rep    movsw
  57.         pop    di            ;Restore pointer to string.
  58.         pop    es
  59. ;
  60. DidByte:    pop    si
  61.         popf
  62.         pop    ax
  63.         pop    cx
  64.         pop    ds
  65.         pop    bp
  66.         clc
  67.         ret
  68. ;
  69. BadStrDupl:    pop    si
  70.         popf
  71.         pop    ax
  72.         pop    cx
  73.         pop    ds
  74.         pop    bp
  75.         stc
  76.         ret
  77. sl_strdupl    endp
  78. ;
  79. ;
  80. stdlib        ends
  81.         end
  82.