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

  1. /*---------------------------------------------------------------------------
  2.  * filename - allocmem.cas
  3.  *
  4.  * function(s)
  5.  *        allocmem - allocates DOS memory segment
  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 <dos.h>
  22. #include <_io.h>
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name        allocmem - allocates DOS memory segment
  27.  
  28. Usage        int allocmem(unsigned size, unsigned *seg);
  29.  
  30. Prototype in    dos.h
  31.  
  32. Description    uses the MS-DOS system call 0x48 to allocate a block of free
  33.         memory and returns the segment address of the allocated block.
  34.  
  35. Return value    returns -1 on success.  In the event of an error, a number
  36.         (the size of the largest available block) is returned
  37.  
  38. *---------------------------------------------------------------------------*/
  39. int allocmem(unsigned size, unsigned *segp)
  40. {
  41. asm    mov    ah, 48h
  42. asm    mov    bx, size
  43. asm    int    21h
  44. asm    jc    allocmemFailed
  45.  
  46. asm    LES_    di, segp
  47. asm    mov    ES_ [di], ax
  48.     return(-1);
  49.  
  50. allocmemFailed:
  51. asm    push    bx
  52.     __IOerror(_AX);
  53. asm    pop    ax
  54.     return (_AX);
  55. }
  56.