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

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. ; strcpy- Copies string pointed at by es:di to string pointed at by dx:si.
  6. ;      (Sorry for the ackward use of registers, this matches the rest
  7. ;       of the standard library though).
  8. ;
  9. ; inputs:
  10. ;        es:di-    Zero-terminated source string.
  11. ;        dx:si-  Buffer for destination string.
  12. ;
  13. ; outputs:    es:di-    Points at destination string.
  14. ;
  15. ; Note: The destination buffer must be large enough to hold the string and
  16. ;    zero terminating byte.
  17. ;
  18.         public    sl_strcpy
  19. ;
  20. sl_strcpy    proc    far
  21.         push    ds
  22.         push    cx
  23.         push    ax
  24.         pushf
  25.         push    si
  26. ;
  27.         cld
  28.         mov    al, 0
  29.         mov    cx, 0ffffh
  30.         push    di
  31.     repne    scasb
  32.         pop    di
  33.         neg    cx
  34.         mov    ax, es
  35.         mov    ds, ax
  36.         mov    es, dx
  37.         xchg    si, di
  38.         dec    cx
  39.         shr    cx, 1
  40.         jnc    CpyWrd
  41.         lodsb
  42.         stosb
  43. CpyWrd:    rep    movsw
  44. ;
  45. DidByte:    pop    si
  46.         popf
  47.         pop    ax
  48.         pop    cx
  49.         pop    ds
  50.         mov    es, dx
  51.         mov    di, si
  52.         ret
  53. sl_strcpy        endp
  54. ;
  55. ;
  56. stdlib        ends
  57.         end
  58.