I am in dire need of help. I have been allocating storage space
in assembly by creating multiple segments, with vacant values. I would
like to allocate this memory from DOS at runtime and only as needed.
currently i am working on a project that needs two 64k blocks of memory
allocated at runtime.
Unfortunately the DOS systems call (allocate memory) returns error.
SOME ONE TOLD ME THAT I WOULD HAVE TO RESIZE THE MEMORY MY PROGRAM IS
USING SINCE DOS GIVES EXECUTES ALL AVAILABLE MEMORY.
how can i determince how much memory my program is using (i have an
intuitive idea)?
how can i resize the amount of memory my program uses and free up space
for runtime allocation of memory?
any other details i must be aware of with regards to amount of memory
allocated?
any help will be appreciated.
due to school and work obligations i may not get your message if posted
to the news group please forward to my email address
thanks in advance!!
SAM...@worldnet.att.net
I am at a point in assembly programming where my programs are beginning
to get more complex (no matter how much optimizing i do). I swear that
once this project is done I will force myself to learn PROTECTED
MODE!!!!
.COM files are allocated all of available DOS memory. You can get
their size by defining a label at the end and using it in a
calculation to figure what's needed and what's not.
.EXE files are allocated memory according to their maximum value in
their header at the beginning of the program file. If you use EXEHDR,
you can modify this value. Just type EXEHDR /? to get the option
formats and then use it to shrink the initial allocation.
You can look at section 27 of the x86 FAQ, as well. It might help
you.
Jon
On 8 Sep 1997 04:08:47 GMT, SAM...@worldnet.att.net wrote:
>hello all:
>
> I am in dire need of help. I have been allocating storage space
>in assembly by creating multiple segments, with vacant values. I would
>like to allocate this memory from DOS at runtime and only as needed.
>currently i am working on a project that needs two 64k blocks of memory
>allocated at runtime.
>
>Unfortunately the DOS systems call (allocate memory) returns error.
>SOME ONE TOLD ME THAT I WOULD HAVE TO RESIZE THE MEMORY MY PROGRAM IS
>USING SINCE DOS GIVES EXECUTES ALL AVAILABLE MEMORY.
>
>how can i determince how much memory my program is using (i have an
>intuitive idea)?
>
>how can i resize the amount of memory my program uses and free up space
>for runtime allocation of memory?
>
>any other details i must be aware of with regards to amount of memory
>allocated?
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 4.0 Business Edition
mQENAjNujBEAAAEIAMVxxCHy2v3+ITzuKpmminx0qmnh2HHAQUyQaFwTKazWk/jQ
igI/wRV3t/RNqDEwCghKjD8MSPHgJEE3YuAa28JdUn29mX0Wr7oA0j+LA9nWmwaT
NsUMCnLP2oKn0QIN8q/qIhQcbcOfg7wOAMnYXPWl7ZAmO14mRTaIrpK+OyhkKHKF
A8UoBvBCAncvuZ5OOFURwXnwEWCT+xZ9enj6izNlfVMGZvItgjFgNEW7rurEoCzm
lWwPYlc06HhpmNeB65zTIKfELysKfxl1/octamHNOndauDgn6G0OWvweve7Bc6ai
yLsZAqvVF9P9f923SuNY26dRwEF+FWvnB+SfdxMABRG0KCJKb25hdGhhbiBLaXJ3
YW4iPGpraXJ3YW5AaXgubmV0Y29tLmNvbT6JAJUDBRAzezvrSL8YK8jpvdEBAbwU
A/9HVcJDaLm1ugAfHwiekAfSxU3gt0UV9jQwOJjbmqhtRn/YZUrQffdPNhqDsEgV
hKLivIlJT6niaASBMpVNAt7PcB+J9NKkte0aTP1SPjflgZu8fKg9aM5W5EHCeeY8
0WY/EsYDewXZWK1zFITnze73yssm4DA/TyDg9gT5f5+DCg==
=PN2I
-----END PGP PUBLIC KEY BLOCK-----
On 8 Sep 1997 04:08:47 GMT, SAM...@worldnet.att.net wrote:
>hello all:
>
> I am in dire need of help. I have been allocating storage space
>in assembly by creating multiple segments, with vacant values. I would
>like to allocate this memory from DOS at runtime and only as needed.
>currently i am working on a project that needs two 64k blocks of memory
>allocated at runtime.
>
>Unfortunately the DOS systems call (allocate memory) returns error.
>SOME ONE TOLD ME THAT I WOULD HAVE TO RESIZE THE MEMORY MY PROGRAM IS
>USING SINCE DOS GIVES EXECUTES ALL AVAILABLE MEMORY.
>
>
>how can i determince how much memory my program is using (i have an
>intuitive idea)?
>
>how can i resize the amount of memory my program uses and free up space
>for runtime allocation of memory?
Well, if your app's a com file, try appending a dummy label at the end
of it and write the following line
org 0100h
Start_of_prog:
mov bx, end
shr bx,04 ;(mov cl,04 - shr bx,cl, if you have a 8086)
....your prog....
end:
If you use A86, there is no need to append the label, the compiler
will traslate the label end with the address of your program's end.
If you are writing an exe file, well, you have to calculate your
program size group per group. Try reading the map files of the linker,
or use more than a dummy label... I never had to determine exactly my
exe-program size - mainly for I prefer writing coms, there is no need
for the clumsy syntax directed to the linker, and 65536 (oh, I forgot
the PSP: 65536 - 256) bytes are enough for my asm code.
Then you may resize the block of memory dos allocated for you, using
service 4ah of int 21h. BX must contain the number of paras you need
for your program, and it's already been set by the previous
instructions.
;following shr ax,04
push cs
pop es ;segment of the block to resize (not needed if es=cs)
mov ah, 04ah
int 21h
>any other details i must be aware of with regards to amount of memory
>allocated?
>
I guess you know how to get allocate memory. Just in case...
mov ah,048h ;service 48h
mov bx, number_of_paragraphs_needed ;
int 21h
;if the carry flag ain't set, AX:0000 is the address of the mem you
allocated.
Remember to free the mem when you have finished, using int 21h
serv.048h (ES must point to the segment of the mem you need to free-
returns carry if error, and you're usually are in big troubles -
namely a system crash)
>any help will be appreciated.
>due to school and work obligations i may not get your message if posted
>to the news group please forward to my email address
>
>thanks in advance!!
>SAM...@worldnet.att.net
>
>I am at a point in assembly programming where my programs are beginning
>to get more complex (no matter how much optimizing i do). I swear that
>once this project is done I will force myself to learn PROTECTED
>MODE!!!!
You're not in hurry. Protmode won't make a better man out of you :-) I
still don't understand what is wrong with real mode. Somebody told me
that simple problems need simple solutions (K.I.S.S. pattern - Keep It
Simple, Stupid) - so, simple programs need real mode.
Am I wrong?
Zello
>hello all:
>
> I am in dire need of help. I have been allocating storage space
>in assembly by creating multiple segments, with vacant values. I would
>like to allocate this memory from DOS at runtime and only as needed.
>currently i am working on a project that needs two 64k blocks of memory
>allocated at runtime.
>
>Unfortunately the DOS systems call (allocate memory) returns error.
>SOME ONE TOLD ME THAT I WOULD HAVE TO RESIZE THE MEMORY MY PROGRAM IS
>USING SINCE DOS GIVES EXECUTES ALL AVAILABLE MEMORY.
>
>
>how can i determince how much memory my program is using (i have an
>intuitive idea)?
>
>how can i resize the amount of memory my program uses and free up space
>for runtime allocation of memory?
>Well, if your app's a com file, try appending a dummy label at the end of it and write the following line
>org 0100h
>Start_of_prog:
> mov bx, end
> shr bx,04 ;(mov cl,04 - shr bx,cl, if you have a 8086)
>....your prog....
>end:
I really dunno what I was thinkin to while writing this letter, but
let me tell you I was watching the Miss Italia contest on TV. Of
course, the right example is
org 0100h
Start_of_prog:
mov bx,end
add bx,0fh ;Get the paras your program
shr bx,04 ;needs
etc.
You can make the sum at compile time
Start_of_prog:
mov bx, end + 0fh
shr bx,04
etc..
Sorry.
Ciao.
Zello
SAM...@worldnet.att.net wrote in article
<341679dd...@news.magicnet.net>...
> Unfortunately the DOS systems call (allocate memory) returns error.
> SOME ONE TOLD ME THAT I WOULD HAVE TO RESIZE THE MEMORY MY PROGRAM IS
> USING SINCE DOS GIVES EXECUTES ALL AVAILABLE MEMORY.
First, I assume you are refering to "DOS" memory (low 640k).
Not quite true.. COM programs are allocated all of DOS memory when loaded.
EXE programs are allocated only the defined amount of memory required by
the program. If you need additional memory in an EXE file, you must get it
allocated form DOS (int 21). If you attempt to get more "DOS" memory
within a COM program, you will get an error return. It has all been
allocated when loading.
> how can i resize the amount of memory my program uses and free up space
> for runtime allocation of memory?
Two ways....
Make your program an EXE file... OR
Release all unneeded memory at the start of your COM file (int 21)
Hmmm.. I thought most .EXEs didn't bother to document the maximum
amount of memory they required in their headers, and consequently got
all memory as well.
> Release all unneeded memory at the start of your COM file (int 21)
Use INT 21h/AH=4Ah (SETBLOCK). You need to input the number of
paragraphs (16 byte blocks) which you want retained. Don't forget to
(1) round up, (2) add a paragraph for your Memory Control Block (the
paragraph preceding your PSP, declaring the amount of memory taken
up by your program). Oh yeah, make sure your stack pointer points
somewhere within that block first, too (e.g., MOV SP,100h if you don't
need much stack and are done with the command line -- in a .COM.) If
you aren't interested in environment variables, or you're done
processing them, you can also free (INT 21h/AH=49h) your environment
block (pointer located at offset 2Ch in your PSP).
--Jeroen--------------------------------------------------
Tiggelman J.Tig...@pi.net (private)
>"James Canty" <J-P....@worldnet.att.net> wrote:
>>> how can i resize the amount of memory my program uses and free up space
>>> for runtime allocation of memory?
>>Two ways....
>> Make your program an EXE file... OR
>
>Hmmm.. I thought most .EXEs didn't bother to document the maximum
>amount of memory they required in their headers, and consequently got
>all memory as well.
The EXE header has a place for a minimum and a maximum value. Many
linkers just past in 0FFFFh into the maximum field, though. Easy to
change, if desired. They often get all of memory, as you describe,
for this reason, but it's not intrinsic to an EXE that they do so.
Jon
Sure, what I wrote implied they had a maximum value, and it's pretty
clear that a minimum is needed. :-|
>linkers just past in 0FFFFh into the maximum field, though. Easy to
>change, if desired. They often get all of memory, as you describe,
>for this reason, but it's not intrinsic to an EXE that they do so.
Right. Apparently I was unclear, but what I meant was just that "make
your program an .EXE file" was not quite all there was to it. ;-)
--Jeroen--------------------------------------------------
Tiggelman J.Tig...@pi.net (private)