home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / MEMSET.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.1 KB  |  84 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. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <mem.h>
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name        setmem - sets memory to value
  26.  
  27. Usage        void setmem(void *addr, unsigned len, char val);
  28.  
  29. Prototype in    mem.h
  30.  
  31. Description    sets the len bytes of the block pointed to by addr to
  32.         val
  33.  
  34. Return value    nothing
  35.  
  36. *------------------------------------------------------------------------*/
  37. void setmem(void *addr, unsigned len, char val)
  38. {
  39. #if !(LDATA)
  40.     _ES = _DS;
  41. #endif
  42. asm    LES_    di, addr
  43. asm    mov    cx, len
  44. asm    mov    al, val
  45. asm    mov    ah, al
  46. asm    cld
  47.  
  48. asm    test    di, 1
  49. asm    jz    isAligned
  50. asm    jcxz    done
  51. asm    stosb
  52. asm    dec    cx
  53. isAligned:
  54. asm    shr    cx, 1
  55. asm    rep    stosw
  56. asm    jnc    noOdd
  57. asm    stosb
  58. noOdd:
  59. done: ;
  60. }
  61.  
  62.  
  63. /*-----------------------------------------------------------------------*
  64.  
  65. Name        memset - sets memory to value
  66.  
  67. Usage        void *memset(void *src, int c, size_t n);
  68.  
  69. Prototype in    mem.h
  70.  
  71. Description    sets the n bytes of the block pointed to by src to
  72.         c.
  73.  
  74. Return value    src
  75.  
  76. *------------------------------------------------------------------------*/
  77. #undef memset                   /* not an intrinsic */
  78. void *_CType memset(void *src, int c, size_t n)
  79.   {
  80.   setmem( src, n, c );
  81.   return( src );
  82.   }
  83.  
  84.