flat assembler
Message board for the users of flat assembler.

Index > Main > Is a variable with a dot located on the stack?

Author
Thread Post new topic Reply to topic
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
If I do:

proc a
local blah:DWORD
...
ret
endp

then blah is located on the stack and is discarded when the procedure returns.

Now if I do:

proc b
jmp @F
blah dd 0
@@:
...
ret
endp

then blah is in heap and is global to other procedures.

But then if I do:

proc c
jmp @F
.blah dd 0
@@:
...
ret
endp

then .blah appears to be local to the procedure as in proc a example.

Question:
In proc c example, is .blah also located on the stack and discarded when the procedure returns?

Chris
Post 18 Feb 2007, 21:35
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
first of all: you can't name procedure just "c" Wink
but this may be also problem in macro
Post 18 Feb 2007, 21:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
ChrisLeslie: The name of a variable has nothing to do with where it's located. Putting a . before its name makes it local, but this is just a matter of scope (where you can access it from). In both your second and third examples the variable is statically allocated.
Post 18 Feb 2007, 22:12
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
Goplat wrote:
Putting a . before its name makes it local, but this is just a matter of scope (where you can access it from). In both your second and third examples the variable is statically allocated.
This mean it's neither on the stack nor on the heap, but "inside, bertween" your actual code, which is very strange for C-asm beginners to understand.
Post 19 Feb 2007, 22:18
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
Subsequent testing shows that "proc b' and "proc c" do infact retain the old values in "blah" upon reentry to the procedure. Therefore "blah" is static for both, but static and local for "proc c".

vid - The name "proc c" is just hypothetical for the discussion. Wink

Chris
Post 20 Feb 2007, 22:13
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
chrisleslie: starting label name with "." only makes NAME local (to last non-local name), not content addressed by that label.

Code:
proc a
.x:   ;this defines label a.x
endp

proc b
.x:   ;this defines label b.x
endp
    


this is all that "." does.
Post 20 Feb 2007, 23:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Chris: if you are C coder, you may think of it this way:

- label not starting with "." defines namespace
- label starting with "." is local symbol in namespace. It's name is appended to namespace, so ".x" in namespace "AAA" becomes "AAA.x".
Post 20 Feb 2007, 23:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
And if you need some local variables on the stack, you must use some esp/rsp modifying code either by yourself or use a macro or that
Post 21 Feb 2007, 01:49
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-2020, Tomasz Grysztar.

Powered by rwasa.