flat assembler
Message board for the users of flat assembler.
Index
> Windows > return local variable. |
Author |
|
JohnFound 01 Sep 2012, 16:24
The locals variables are, well, "local". They does not exists outside of their scope - i.e. "secondproc" in your example. You should not refer to them after secondproc exits.
Also, the local variables should be undefined, but I am not sure about "locals" macro from FASM package. Maybe it generates the initialization code. (If so, IMHO, it is not a good practice at all, because it hides important code from the user). |
|||
01 Sep 2012, 16:24 |
|
Overflowz 01 Sep 2012, 16:33
Hi, I'm aiming C-style returns to avoid much global variables. I tried moving them with ESI, EDI and rep movsb and it succeed. How C programs return local variables then ?
Thanks. |
|||
01 Sep 2012, 16:33 |
|
JohnFound 01 Sep 2012, 18:45
I don't know C. In Pascal you can't return pointer to local variables. You can return the value of the local variable, but it is not the same.
|
|||
01 Sep 2012, 18:45 |
|
bitshifter 01 Sep 2012, 19:36
Overflowz wrote: How C programs return local variables then ? Code: int GetValue (void) { static int value = 666; return value; } The scope is local but storage is global. You could do something like this in fasm to hide variables... Code: GetValue: mov eax, [.private_data] ret .private_data: dd 666 ;gets stored in code section! And we could still access it globally like... Code: mov eax, [GetValue.private_data] Hope this helps... _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
01 Sep 2012, 19:36 |
|
Overflowz 02 Sep 2012, 01:21
That's exactly what I was looking for! Thank you!
|
|||
02 Sep 2012, 01:21 |
|
typedef 02 Sep 2012, 04:06
This is beginners stuff. I thought you knew this already.
Not being rude or something. http://programming-motherfucker.com/become.html lol |
|||
02 Sep 2012, 04:06 |
|
kalambong 02 Sep 2012, 08:30
A real nice page, unfortunately, not very pc
|
|||
02 Sep 2012, 08:30 |
|
AsmGuru62 02 Sep 2012, 11:58
Global variables are awesome!
No avoiding them in ASM. So, Overflowz, you wish to avoid something like a string "some text" put into a global storage? The only way to do it is put all strings into a file and load it at startup: Code: FILE MESSAGES.TXT: ------------------------------------------------- {0001}A line of text for some message. {0002}Another line of text for a message box. ------------------------------------------------- And then access the text by an index. Any 'normal' EXE however has all these strings as global variables. The values in {} are just for your reference, so you know which index refers to which text. When loading the file simply skip 6 bytes from the line beginning to get an address to string. |
|||
02 Sep 2012, 11:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.