home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / MEMCPY.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.0 KB  |  73 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - memcpy.cas
  3.  *
  4.  * function(s)
  5.  *        memcpy - copy a block of n bytes from src to dst
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <mem.h>
  22.  
  23. #undef memcpy                  /* not an intrinsic */
  24.  
  25. /*-----------------------------------------------------------------------*
  26.  
  27. Name        memcpy - copy a block of n bytes from src to dst
  28.  
  29. Usage        void *memcpy(void *dst, const void *src, size_t n);
  30.  
  31. Prototype in    mem.h & string.h
  32.  
  33. Description    memcpy copies  a block of n  bytes from src to    dst.
  34.         No overlap checking is performed.
  35.  
  36. Return value    memcpy returns dst
  37.  
  38. *------------------------------------------------------------------------*/
  39.  
  40. #if    1    /* No overlap checking version */
  41.  
  42. void *memcpy(void *dst, const void *src, size_t n)
  43. {
  44. #if !(LDATA)
  45.     _ES = _DS;
  46. #endif
  47. #if    defined(__LARGE__) ||  defined(__COMPACT__)
  48. asm    mov    dx,ds        /* save ds */
  49. #endif
  50. asm    LES_     di, dst
  51. asm    LDS_     si, src
  52. asm    mov    cx,n
  53. asm    shr    cx,1
  54. asm    cld
  55. asm    rep    movsw
  56. asm    jnc    cpy_end
  57. asm    movsb
  58. cpy_end:
  59. #if    defined(__LARGE__) || defined(__COMPACT__)
  60.     asm    mov    ds,dx        /* restore */
  61. #endif
  62.     return(dst);
  63. }
  64.  
  65. #else        /* Overlap checking version    */
  66.  
  67. void *memcpy(void *dst, const void *src, size_t n)
  68. {
  69.     movmem(src,dst,n);
  70.     return(dst);
  71. }
  72. #endif
  73.