News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

.stack 100h

Started by cork, July 15, 2010, 09:39:25 PM

Previous topic - Next topic

cork

I often see a stack defined at the top of a source file for x86 assembly language examples, with a line such as ".stack 100h".

Do I need to do this? What happens if I don't and I assemble my program using MASM32? Does it give it a default stack of some particular size? Or does it not matter because Windows will grow the stack?

This is how I start out my source files, currently:

.486                             ; For 80486 CPUs or higher.
.model flat, stdcall        ; Windows is always the 32-bit FLAT model
option casemap:none    ; Use case-sensitive labels.

I'm using MASM32 and 64-bit Vista, and am creating EXEs to run on 32-bit or 64-bit Windows.


dedndave

you may see that in 16-bit programs - it isn't really necessary for 32-bit
i think there is something like 1 Mb default allocated (i forget - lol)
but, in windows, the more stack space you use, the more is assigned
in fact, that can be a problem if you subtract some large number from ESP and expect it to be there
you have to "probe down" the stack, one page at a time so that the pages get commited (4 Kb pages as i recall)

as for 16-bit programs - i would recommend at least 512 bytes - lol - 100h goes away pretty fast

hutch--

For win32 PE files you use a linker option /STACK: with the "stackreserve" and "stackcommit" arguments.


\MASM32\BIN\Link.exe /SUBSYSTEM:WINDOWS /STACK:0x400000,0x400000 yourapp.obj rsrc.res


Note that the hex notation is in C format. This is a 1 meg stack with 1 meg committed.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

clive

Quote from: hutch-- on July 16, 2010, 12:26:36 AM
For win32 PE files you use a linker option /STACK: with the "stackreserve" and "stackcommit" arguments.


\MASM32\BIN\Link.exe /SUBSYSTEM:WINDOWS /STACK:0x400000,0x400000 yourapp.obj rsrc.res


Note that the hex notation is in C format. This is a 1 meg stack with 1 meg committed.

Hutch you must be using some funny Australian math, isn't that 4 MB?
It could be a random act of randomness. Those happen a lot as well.

oex

Vista compatible :bdg
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

if you link with stack committed that way, do you still need to probe it down ?

(Clive - everything is upside-down or backwards, down there)

hutch--

 :bg

I usually confess to senile decay but in this case its just snatching a familiar number unthought. Try 0x100000.  :P

Dave,

PE specification ALA Microsoft pecoff.doc, later version is pecoff.docx.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

oex

Quote from: dedndave on July 16, 2010, 01:39:40 AM
(Clive - everything is upside-down or backwards, down there)

:lol Their prime minister comes from the other side of the planet.... T :bg
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

hutch--

Yeah yeah but at least we have a Welsh redhead, you can keep Cameron.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php