home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / MALLOC / CALLOC.ASM next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.3 KB  |  39 lines

  1. ;****************************************************************************
  2. ; Filename: CALLOC.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.3
  5. ;  Created: 1995.03.10
  6. ;  Updated: 
  7. ;****************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: PVOID @calloc(ULONG items,ULONG size)
  12. ;  Comment: Allocates the first available memory block which is big enough
  13. ;           and clears it. The size to allocate is items*size.
  14. ;    Input: Eax - number of items to allocate
  15. ;           Edx - size of block to allocate in bytes
  16. ;  Returns: Pointer to the allocated block or 0 if it failed.
  17. ;****************************************************************************
  18.  
  19.     Include    STDDEF.INC
  20.     Include "MEMORY.INC"
  21.  
  22.     Codeseg
  23.  
  24. Proc    calloc ,2
  25.         Imul    Eax,Edx
  26.                 Push    Eax
  27.         Call    @malloc        ; Call the good ol' malloc
  28.                 POP     Ecx             ; Get size allocated
  29.         TestZ    Eax        ; If malloc returned a NULL pointer
  30.         Jz    @@Exit        ; exit immediately
  31.                 Push    Eax
  32.                 Clear    Edx        ; Get blocksize and clear the fill value
  33.         Call    @memset
  34.                 Pop     Eax
  35. @@Exit:        Ret
  36. Endp    
  37.  
  38.     End
  39.