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

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