Muta,
> I have startup code below that resizes that memory, as
> per rules I no longer remember.
...
> mov ax, sp
> mov cl, 4
> shr ax, cl ; get sp into pages
When a COM runs SP is set to the end of the SS segment. As a COM has all
the segments overlapping its upto how big your program is how much stack you
are actually reserving. But looking at my own programs I don't think that
reserving 60KB stack for a 4KB program is normally called for.
Hence I set SP myself (sometimes even to the programs top at 0100h) and
instead use a LASTBYTE label to figure out how much room I actually need
calculated the # of pages from it :
- - - - - - - - - - - - - - - - - - - -
lea sp,[StackTop] ;Set new Stack-top
mov bx,(offset LASTBYTE)+000Fh ;number of bytes in program + round-up
mov cl,04h ;convert to pages
shr bx,cl ;/
mov ah,4ah ;resize program space
int 21h ;/
jc @@Main_Error ;ERROR : Out of Memory !
- - - - - - - - - - - - - - - - - - - -
As you might see, I also made sure I could actually allocate it, as its
possible a COM gets loaded in a memory fragment thats not actually large
enough to hold it and the "extra" memory it needs.
> So for all executables, all of memory is allocated until
> released?
Yes for a .COM style program, and "it depends" for a .EXE style one - as
that latter one has got a header wich specifies lots of stuff.
> tlink (which is what I originally used) puts x'ffff' as the number
> of paragraphs to allocate, meaning allocate all memory.
Indeed it does (using Borlands Tasm v4.1 and TLink v7.1). I've never been
able to find a "minimize footprint" switch or setting, which has irked me to
no end. You see, one of the fields in an .EXEs header is
"min_extra_paragraphs" , containing - you guessed it - exactly how much it
needs. As such I wrote a small program that copies that field into the
"max_extra_paragraphs" one (which is, in our case, the culprit), recalculate
the SS:SP value from it and put it into their respective fields.
From than on the OS does, for the .EXE, all the work for me, allowing me to
drop the "shrink my memory" code from it. :-)
Regards,
Rudy Wieser