Ref Programmers Journal Vol 9.2 Pg 10

When DOS loads an EXE file into a memory block, it alocates the whole block. When your program starts, it already owns most of the available memory and cannot allocate any more. If you shrink the program memory block to the minimum required, you can then reallocate as necessary. The following is a short demonstration program.

; Code from John Otken

     dosseg
     .model small
     .stack
     .code


;; main
;
main proc
     mov  bx,offset stack+15   ; compute program size in paragraphs
     mov  cl,4                 ; SS != DGROUP in program
     shr  bx,cl
     add  bx,data
     mov  ax,es                ; ES == Struc -Program Segment Prefix
     sub  bx,ax

     mov  ah,4Ah               ; Shrink program's memory block
     int  21h		       ; Int\21f\4A

     mov  ah,48h               ; Allocate 16 paragraphs of memory
     mov  bx,16                ; (16 paragraphs == 256 bytes)
     int  21h		       ; Int\21f\48

     mov  ax,4C00h             ; exit program
     int  21h		       ; Int\21f\4C
main endp

     end main