flat assembler
Message board for the users of flat assembler.
Index
> Windows > The Stack Under Win32 |
Author |
|
baldr 29 Mar 2010, 07:30
Tyler,
How do you think, where do automatic variables live? |
|||
29 Mar 2010, 07:30 |
|
Tyler 29 Mar 2010, 07:48
What are automatic variables? Do you mean environment variable or argc/argv, or something else?
|
|||
29 Mar 2010, 07:48 |
|
sinsi 29 Mar 2010, 07:57
Local vars live below esp ([esp-x]), the return address of a call lives at [esp+0] and parameters live at [esp+4*n].
Anything above your parmeters is, well, anything - leftover parameters from old calls, leftover locals from old calls etc. |
|||
29 Mar 2010, 07:57 |
|
revolution 29 Mar 2010, 08:05
Everything (including local variables) should "live" above esp. Putting stuff below esp is generally not a good idea since it will likely get clobbered next time you push or call something.
|
|||
29 Mar 2010, 08:05 |
|
Tyler 29 Mar 2010, 08:10
Oooh, I see what I said wrong. When I said below, I was thinking of the stack as a literal stack, I'm actually adding to esp.
But what is all that? I get that its some functions params, but what is it for, and what would happen if I changed it? |
|||
29 Mar 2010, 08:10 |
|
sinsi 29 Mar 2010, 08:13
oops, yeah, esp != ebp.
Everything should be [esp+something]. |
|||
29 Mar 2010, 08:13 |
|
zhak 29 Mar 2010, 09:12
Tyler wrote: But what is all that? I get that its some functions params, but what is it for, and what would happen if I changed it? This can be the garbage, or this can be parameters of parent procedures - the procedures from which your current procedure is called. |
|||
29 Mar 2010, 09:12 |
|
baldr 29 Mar 2010, 09:16
zhak,
Not only parameters: local (i.e. automatic) variables are allocated on stack as well. |
|||
29 Mar 2010, 09:16 |
|
zhak 29 Mar 2010, 09:17
Yes, sure. and local variables as well
|
|||
29 Mar 2010, 09:17 |
|
baldr 29 Mar 2010, 10:12
Tyler,
In Pascal (oh yeah, Algol family… Dijkstra, Wirth, Backus and Naur) inner procedures can access outer procedures' parameters and variables. In most implementations this is done via stack (cf. enter). |
|||
29 Mar 2010, 10:12 |
|
Tyler 04 Apr 2010, 03:09
I guess what I thought was weird about this(~3am when I posted), is that there are strings on the stack, why? I've always assumed the only way(only EASY way) to pass strings, is with a pointer, right?
|
|||
04 Apr 2010, 03:09 |
|
revolution 04 Apr 2010, 04:21
Code: ;... sub esp,1024 ;make space for a string mov ebx,esp ;point to it invoke lstcpy,ebx,"I'm a string" invoke SomeAPIFunction,ebx ;pass a string pointer to a function add esp,1024 ;we are finished with it ;... |
|||
04 Apr 2010, 04:21 |
|
Tyler 04 Apr 2010, 04:33
Oh, my problem is how I tend to think of the stack as a mechanism that can ONLY be access in reversed order(FIFO), but I get it now, I see that the stack can be used for much more. Thanks for clarifying.
|
|||
04 Apr 2010, 04:33 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.