VirtualQuery() can be used to get the stack base and size:
mainCRTStartup PROC c
local mbi:MEMORY_BASIC_INFORMATION
invoke VirtualQuery, addr mbi, addr mbi, sizeof MEMORY_BASIC_INFORMATION
.if ( eax )
;invoke printf, CStr("BaseAddress=%X",lf), mbi.BaseAddress
;invoke printf, CStr("RegionSize=%X",lf), mbi.RegionSize
mov esi, mbi.AllocationBase
invoke printf, CStr("stack base=%X",lf), esi
lea edi, mbi
and di, 0F000h
.repeat
add edi, 1000h
invoke VirtualQuery, edi, addr mbi, sizeof MEMORY_BASIC_INFORMATION
.until eax == 0 || esi != mbi.AllocationBase
sub edi, esi
invoke printf, CStr("stack size=%X",lf), edi
.else
invoke GetLastError
invoke printf, CStr("VirtualQuery(%X) failed [%X]",lf), addr mbi, eax
.endif
invoke ExitProcess, 0
mainCRTStartup endp
to set the stack size from inside the program, use the .drectve section:
option dotname
.drectve segment info
db "-stack:0x1000000,0x1000 "
.drectve ends