mov bx, MemSize ;amount of memory, in paragraphs
mov ax, SegmentMem ;segment address of memory to resize
mov es, ax
mov ah, 4Ah ;Set Memory Block Size
int 21h
jc error_handler ;carry set means error
Set Memory Block Size (Function 4Ah) can be used to change the size of a memory segment previously allocated by Allocate Memory (Function 48h) or to change the amount of memory originally allocated to a program by MS-DOS.
MemSize
Specifies the new size of the memory block, in paragraphs. The new size may be smaller or larger than the current size of the block.
SegmentMem
Specifies the segment address of the memory block to resize. If the memory block was allocated by Allocate Memory, this parameter must be the segment address returned by that function.
If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:
Value | Name |
0007h | ERROR_ARENA_TRASHED |
0008h | ERROR_NOT_ENOUGH_MEMORY |
0009h | ERROR_INVALID_BLOCK |
If this function returns 0008h (ERROR_NOT_ENOUGH_MEMORY), the BX register contains the number of paragraphs in the largest available memory block.
This function returns 0009h (ERROR_INVALID_BLOCK) if a program tries to change the size of a memory block that was not allocated by Allocate Memory or by MS-DOS when the program was started.
If this function is used to decrease the size of a memory block, the memory above the new limit is no longer owned by the program and should not be used. If this function is used to increase the size of a memory block, the contents of the new memory are not defined.
Function 48h Allocate Memory
Function 49h Free Allocated Memory