home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / MEMCPY.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.8 KB  |  75 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.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <mem.h>
  20.  
  21. #undef memcpy                  /* not an intrinsic */
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name            memcpy - copy a block of n bytes from src to dst
  26.  
  27. Usage           void *memcpy(void *dst, const void *src, size_t n);
  28.  
  29. Prototype in    mem.h & string.h
  30.  
  31. Description     memcpy copies  a block of n  bytes from src to  dst.
  32.                 No overlap checking is performed.
  33.  
  34. Return value    memcpy returns dst
  35.  
  36. *------------------------------------------------------------------------*/
  37.  
  38. #if defined(__FARFUNCS__)
  39. #include <_farfunc.h>
  40. #endif
  41.  
  42. #if     1       /* No overlap checking version */
  43.  
  44. void * _FARFUNC memcpy(void *dst, const void *src, size_t n)
  45. {
  46. #if !(LDATA)
  47.         _ES = _DS;
  48. #endif
  49. #if     defined(__LARGE__) ||  defined(__COMPACT__)
  50. asm     mov     dx,ds           /* save ds */
  51. #endif
  52. asm     LES_     di, dst
  53. asm     LDS_     si, src
  54. asm     mov     cx,n
  55. asm     shr     cx,1
  56. asm     cld
  57. asm     rep     movsw
  58. asm     jnc     cpy_end
  59. asm     movsb
  60. cpy_end:
  61. #if     defined(__LARGE__) || defined(__COMPACT__)
  62.         asm     mov     ds,dx           /* restore */
  63. #endif
  64.         return(dst);
  65. }
  66.  
  67. #else           /* Overlap checking version     */
  68.  
  69. void * _FARFUNC memcpy(void *dst, const void *src, size_t n)
  70. {
  71.         movmem(src,dst,n);
  72.         return(dst);
  73. }
  74. #endif
  75.