Allocates a block of memory and returns a pointer to the beginning of the allocated area.
Call with:
AH = 48H
BX = number of paragraphs of memory needed
Returns:
If function successful
Carry flag = clear
AX = base segment address of allocated block
If function unsuccessful
Carry flag = set
AX = error code
BX = size of largest available block (paragraphs)
Notes:
If the function succeeds, the base address of the newly allocated block is AX:0000.
The default allocation strategy used by MS-DOS is "first fit"; that is, the memory block at the lowest address that is large enough to satisfy the request is allocated. The allocation strategy can be altered with Int 21H Function 58H.
When a .COM program is loaded, it ordinarily already "owns" all of the memory in the transient program area, leaving none for dynamic allocation. The amount of memory initially allocated to a .EXE program at load time depends on the MINALLOC and MAXALLOC fields in the .EXE file header. See Int 21H Function 4AH.
Example:
Request a 64 KB block of memory for use as a buffer.
bufseg dw ? ; segment base of new block
.
.
.
mov ah,48h ; function number
mov bx,1000h ; block size (paragraphs)
int 21h ; transfer to MS-DOS
jc error ; jump if allocation failed
mov bufseg,ax ; save segment of new block
.
.
.