flat assembler
Message board for the users of flat assembler.

Index > Windows > local varialbles - stack vs .data section

Author
Thread Post new topic Reply to topic
int0x50



Joined: 19 Jul 2019
Posts: 54
int0x50 07 Aug 2019, 08:56
how do you manage variables within a function? you keep everything in one .data section or you manage through altering esp?
Post 07 Aug 2019, 08:56
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4042
Location: vpcmpistri
bitRAKE 07 Aug 2019, 10:29
Re-entrant code requires keeping the data local, or allocating space: recursion, multi-threaded, etc. Code re-use can benefit from keeping the data local (feels more encapsulated, just copying the code into any project and use it).

Global data is needed for visibility throughout the program, and for persistence throughout execution.

Most software needs a combination of the two approaches.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 07 Aug 2019, 10:29
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 07 Aug 2019, 16:56
int0x50 wrote:
how do you manage variables within a function? you keep everything in one .data section or you manage through altering esp?

There’re such words as prologue and epilogue, and the idea behind them is so widely used that it even got into a standard set of procedure macros shipped with FASM. EBP is also there for a reason.
Post 07 Aug 2019, 16:56
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 799
Location: Russian Federation, Sochi
ProMiNick 07 Aug 2019, 17:33
Until thou got stack overload error thou could keep variables anywhere. In case of growing functional of thour program (stack use) thou will have to start to economy stack resources.
In multythreading app thou will need to economy stack on needs not relative to current thread. Because stack is place for threadvars.
Post 07 Aug 2019, 17:33
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 07 Aug 2019, 17:39
When deciding between global vs local variables I like to think of global variables the same way as files on a disk. If the data makes sense to be stored in a file then it can also make sense to make it global. Otherwise store it locally.

But locally doesn't always have to be on the stack. If you have a large local data set then you can also allocate memory and store it there. And remember to free it before returning to the caller.
Post 07 Aug 2019, 17:39
View user's profile Send private message Visit poster's website Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 763
guignol 07 Aug 2019, 17:40
ok
Post 07 Aug 2019, 17:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.