flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > "Local" in "proc" implementation questio

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 10 Mar 2006, 08:41
Tomasz, hello again!
Please say some words about 'local' macro implementation, especially the way of defining typisized local variables in stack using 'virtual' directive. It will be very helpful for me to know how in different procs can be defined variables with same names without got 'symbol already defined' message. I think without your help i will not catch it.
Thanks and regards.

_________________
Flat Assembler is the best!
Post 10 Mar 2006, 08:41
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Mar 2006, 10:34
how about starting local name with "."?
Code:
proc a
local .loc
endp
proc b
local .loc
endp    
Post 10 Mar 2006, 10:34
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 10 Mar 2006, 11:46
Hi vid!
It is not needed, the following works fine, but i don't catch implementation

Code:
struct ASD

 A  dd  ?
 B  dd  ?
 C  db  ?

ends

proc A 
 local str : ASD
 mov eax,[str.A]
 ret
endp

proc B
 local a : DWORD
 local str : ASD
 mov eax,[str.B]
 ret
endp

 stdcall A
 stdcall B    


Regards.

_________________
Flat Assembler is the best!
Post 10 Mar 2006, 11:46
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 10 Mar 2006, 16:40
The implementation abstract:
Code:
A:                      ; proc A
 virtual at ebp-4
  ..a?0001 dd ?
  a equ ..a?0001
 end virtual

 mov eax,[a]
 ret

restore a               ; endp

B:                      ; proc B
 virtual at ebp-4
  ..a?0002 dd ?
  a equ ..a?0002
 end virtual

 mov eax,[a]
 ret

restore a               ; endp    
Post 10 Mar 2006, 16:40
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 13 Mar 2006, 06:47
Of course it is the obvious decision, but i have made some experiments with your macro package and left only nessesary part. Please explain how it works:

Code:
macro deflocal@proc name,def,val
{
  local ..var
   ..var def val
   name equ ..var
}
 
macro do_local Name,Type,Pos
{

  virtual at Pos
   macro label . ; <- why label is redefined?
   \{
    deflocal@proc .,:, ; <- why it must be done with macro here?
   \}
   Name Type

  end virtual
}


struct ASD
 a   dd ?
 b   dd ?
ends

A:
 do_local a,ASD,esp+4
 retn

restore a

B:
 do_local b,dd,esp+4
 do_local c,ASD,esp+8
 retn

restore b    


Thanks and regards.

_________________
Flat Assembler is the best!
Post 13 Mar 2006, 06:47
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 13 Mar 2006, 09:17
This is done this way so the structures can be put inside locals. The "struct" macro always defined main structure label with the "label" directive, so by re-defining the "label" here you can adjust that definition to your own.
Note that this means that "local" macro will work correctly with structures only if they were defined with official "struct" macro (from the same includes package).
Post 13 Mar 2006, 09:17
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 15 Mar 2006, 15:02
Hi, Tomasz!
Please explain, why i got 'symbol already defined' error in this case?

Code:
macro deflocal@proc name,def,val
{ 
  local ..var 
   ..var def val 
   name equ ..var 
} 
  
macro do_local Name,Type,Pos 
{ 

  virtual at Pos 
   macro label .
   \{ 
    deflocal@proc .,:,
   \} 
   Name Type 
   purge label
  end virtual 
} 


struct ASD 
 a   dd ? 
 b   dd ? 
ends 

A: 
 do_local a,ASD,esp+4 
 retn 

restore a 

B: 
 do_local a,ASD,esp+8
 retn 

restore a    


Thanks and regards.

_________________
Flat Assembler is the best!
Post 15 Mar 2006, 15:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Mar 2006, 15:08
You did not restore the names for all the fields (including "a.a").
Post 15 Mar 2006, 15:08
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 15 Mar 2006, 15:27
But this doesn't work too. Maybe some other implementation needed to restore the values?

Code:
macro deflocal@proc name,def,val
{ 
  local ..var 
   ..var def val 
   name equ ..var 
} 
  
macro do_local Name,Type,Pos 
{ 

  virtual at Pos 
   macro label .
   \{ 
    deflocal@proc .,:,
   \} 
   Name Type 
   purge label
  end virtual 
} 


struct ASD 
 a   dd ? 
 b   dd ? 
ends 

A: 
 do_local a,ASD,esp+4 
 retn 

restore a 
restore a.a
restore a.b

B: 
 do_local a,ASD,esp+8
 retn 

restore a    


Thanks and regards.

_________________
Flat Assembler is the best!
Post 15 Mar 2006, 15:27
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Mar 2006, 15:51
Oh, right, you also did not redefine "dd" to use deflocal@proc.
Post 15 Mar 2006, 15:51
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 16 Mar 2006, 08:09
Thanks, Tomasz!
It works fine.
Regards.
Post 16 Mar 2006, 08:09
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.