Hi,


Someone knows exactly how the stack pointers works ?


On the example BITBLT.ASM, WinMain is :

(...)
invoke LoadIcon,hInst,500 ; icon ID


That Is equal to:

(...)
push ebp
mov ebp, esp
add esp, 0FFFFFFA4h
(...)
call LoadIconA

How did the esp achieved the value 0FFFFFFA4h ??? What this value is realted ? To the size of the previous function ?

Is there a way that i can calculate the stack pointer and see how it was fixed or called inside a function ?


Regards,

Beyond2000!
Posted on 2002-05-02 06:07:13 by Beyond2000!
You seem to be getting confused between the LoadIcon call, and the setting up of the WinMain function.

As the WinMain function has local variables declared in it, these are stored on the stack. If you total up the number of bytes used by these locals it will turn out to be 92. Why is this value 92 important?
0FFFFFFA4h == -92
The compiler is adding -92 rather than subtracting 92 to from the value. By doing this it has reserved enough space on the stack to store all your local variables.

Mirno
Posted on 2002-05-02 06:55:57 by Mirno
This value is not so important...I'm just trying to understand how the assembler knows how many bytes he has to use in order to fix the stack.


Since The Winmain function is written as:

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

;====================
; Put LOCALs on stack
;====================

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD
(....)


How the assembler knew how many bytes he had to insert, since they are all represented as single DWORDs ?
Posted on 2002-05-02 07:05:26 by Beyond2000!
Beyond2000!,

Your question is not a question about assembler but a question about how ML.EXE parses the LOCAL directive before it sets the stack to have enough room to handle the local data.

If you are into writing assemblers or compilers, this would be useful information but its not something you can effect in your assembler code.

Regards,

hutch@movsd.com
Posted on 2002-05-02 07:14:45 by hutch--
The only time i noticed it does was when your passing an array of something defined on the stack as locals:
SomeFunct PROC

LOCAL P1 :POINT
LOCAL P2 :POINT
LOCAL P3 :POINT

..

invoke DrawPolyLine, ..., 3 , addr P1 ; Draw 3 Point Line

Will not work!!! :grin: (i know cause i tried this once).

This is because the stack natually counts down. If memory serves me the correct ordering was:
SomeFunct PROC

LOCAL P3 :POINT
LOCAL P2 :POINT
LOCAL P1 :POINT

..

invoke DrawPolyLine, ..., 3 , addr P1 ; Draw 3 Point Line


Just thought i would point it out :)
:alright:
NaN
Posted on 2002-05-02 07:26:04 by NaN
NaN, that is why you do: LOCAL P[3]:POINT
Posted on 2002-05-02 08:06:47 by bitRAKE
Posted on 2002-05-02 08:53:24 by NaN
push ebp
mov ebp, esp
...
MS-VC compiler loves to do this at the start of every function. And also MS-VC loves to use the EBP register. Dunno why?
Is there a way that i can calculate the stack pointer and see how it was fixed or called inside a function ?
If your creating your own assembler/compiler what you have to do is to tokenize the code and check the parameters of a function then calculate the proper stack size, this is done during tokenizing, determining the token type...but that's another story!!! :grin:
Posted on 2002-05-02 21:07:35 by stryker