home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / MEMSET.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  88 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - memset.cas
  3.  *
  4.  * function(s)
  5.  *        memset - sets memory to value
  6.  *        setmem - sets memory to value
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <mem.h>
  21.  
  22. #undef memset                  /* not an intrinsic */
  23.  
  24. /*-----------------------------------------------------------------------*
  25.  
  26. Name            setmem - sets memory to value
  27.  
  28. Usage           void setmem(void *addr, unsigned len, char val);
  29.  
  30. Prototype in    mem.h
  31.  
  32. Description     sets the len bytes of the block pointed to by addr to
  33.                 val
  34.  
  35. Return value    nothing
  36.  
  37. *------------------------------------------------------------------------*/
  38. #if defined(__FARFUNCS__)
  39. #include <_farfunc.h>
  40. #endif
  41.  
  42. void _FARFUNC setmem(void _FAR *addr, unsigned len, char val)
  43. {
  44. #if !(LDATA)
  45.     _ES = _DS;
  46. #endif
  47. asm LES_    di, addr
  48. asm mov cx, len
  49. asm mov al, val
  50. asm mov ah, al
  51. asm cld
  52.  
  53. asm test    di, 1
  54. asm jz  isAligned
  55. asm jcxz    done
  56. asm stosb
  57. asm dec cx
  58. isAligned:
  59. asm shr cx, 1
  60. asm rep stosw
  61. asm jnc noOdd
  62. asm stosb
  63. noOdd:
  64. done: ;
  65. }
  66.  
  67.  
  68. /*-----------------------------------------------------------------------*
  69.  
  70. Name            memset - sets memory to value
  71.  
  72. Usage           void *memset(void *src, int c, size_t n);
  73.  
  74. Prototype in    mem.h
  75.  
  76. Description     sets the n bytes of the block pointed to by src to
  77.                 c.
  78.  
  79. Return value    src
  80.  
  81. *------------------------------------------------------------------------*/
  82. void * _CType _FARFUNC memset(void *src, int c, size_t n)
  83. {
  84.   setmem( src, n, c );
  85.   return( src );
  86. }
  87.  
  88.