flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to define 'variable' definitions?

Author
Thread Post new topic Reply to topic
Hapkidoyoka



Joined: 03 Mar 2008
Posts: 13
Hapkidoyoka 05 Feb 2009, 21:24
Hello all,

I'm trying to do something like this:
Code:
macro setprefix prefix {
  global_prefix equ prefix
  defvar_count = 0
}

macro defvar name {
  global_prefix#name = defvar_count
  defvar_count = defvar_count+1
}
    
I can't get it to work Sad
I have trawled the forums, read the doc, and tried to figure it out myself.
Can anyone shed some light on this?
Post 05 Feb 2009, 21:24
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 05 Feb 2009, 21:35
Hapkidoyoka, maybe this will work as you need:

Code:
macro setprefix prefix {
  global_prefix equ prefix
  defvar_count = 0
}

macro defvar name {
 match pref , global_prefix
 \{
   pref\#name = defvar_count
 \}
 defvar_count = defvar_count+1
}
    
Post 05 Feb 2009, 21:35
View user's profile Send private message Reply with quote
Hapkidoyoka



Joined: 03 Mar 2008
Posts: 13
Hapkidoyoka 05 Feb 2009, 22:00
Many thanks IronFelix, It works nicely.

Now I've never understood the match directive. I can see what it does, just not a clear how/why.

Thanks again Smile.
Post 05 Feb 2009, 22:00
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 05 Feb 2009, 22:10
You are welcome, Hapkidoyoka. As for "match" - it is very powerful and very useful preprocessor directive.
Post 05 Feb 2009, 22:10
View user's profile Send private message Reply with quote
Hapkidoyoka



Joined: 03 Mar 2008
Posts: 13
Hapkidoyoka 05 Feb 2009, 22:22
Not wanting to start a new thread...
Code:
macro setprefix prefix {
  global_prefix equ prefix
  defvar_count = 0
}

macro defvar name {
 match pref , global_prefix
 \{
   pref\#name = defvar_count
 \}
 defvar_count = defvar_finished - defvar_count+1
}

macro endprefix {
  defvar_finished = defvar_count
}

setprefix lvo
defvar one
defvar two
....
endprefix     

The intent is to define the values in the reverse order. So there is initially an unknown number of them.

Is there some kind of equ 'trick' to accomplish this?
Post 05 Feb 2009, 22:22
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 06 Feb 2009, 17:22
Not a "trick" I think Smile. Just use one EQU name as list of other names, something like this:
Code:
Def@VarList equ

macro addto_equlist ListName,[param]
{
 common
  match any , ListName \{ ListName equ any,param \}
  match     , ListName \{ ListName equ param     \}
}

macro setprefix prefix { 
 global_prefix equ prefix 
} 

macro defvar name {
 addto_equlist Def@VarList, name 
} 

macro reverse_enum_defvars [defvar]
{
 common
  local ind
  ind = 0
 reverse
 match pref , global_prefix
 \{ 
  pref\#defvar = ind
  ind = ind + 1
 \} 
}

macro endprefix {
 match all, Def@VarList
 \{
  reverse_enum_defvars all 
 \} 
} 

setprefix lvo 
defvar one 
defvar two 
endprefix 

display "lvoone = ",lvoone + 48,13,10
display "lvotwo = ",lvotwo + 48,13,10
    

Suppose this will do what you need.
Post 06 Feb 2009, 17:22
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 06 Feb 2009, 17:36
The much simpler correction may be enough:
Code:
macro setprefix prefix {
  global_prefix equ prefix 
  defvar_count = 0 
} 

macro defvar name { 
 match pref , global_prefix  \{ pref\#name = defvar_finished - defvar_count \} 
 defvar_count = defvar_count+1
} 

macro endprefix { 
  defvar_finished = defvar_count 
} 

setprefix lvo 
defvar one 
defvar two

endprefix    
Post 06 Feb 2009, 17:36
View user's profile Send private message Visit poster's website Reply with quote
Hapkidoyoka



Joined: 03 Mar 2008
Posts: 13
Hapkidoyoka 06 Feb 2009, 17:59
IronFelix,
With your previous advice I was coming up with something very similar; So cudos to the teacher.

I'm not sure what the slash does in pref\#name, that got me into a little trouble Confused

Does the @ symbol in Def@VarList do anything special?

I'm up and running, now I can concentrate more on code than macros.

Again you have my thanks, you're a diamond sir.
Post 06 Feb 2009, 17:59
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 06 Feb 2009, 18:29
Too much thanks for such small advice, Hapkidoyoka... You are just welcome.
Tomasz, thank for your correction. And in order not to make a new thread please tell me, what is faster compiled: code with a lot of assembler directives (constants and arithmetic/logical operators), which can increase compile passes I suppose, or using preprocessor where possible (equ, define, match), as it is done only one pass with it? If there are any mistakes in my suggestions, sorry for that.
Post 06 Feb 2009, 18:29
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 06 Feb 2009, 18:30
As for @ symbol - it has no special meaning.
Post 06 Feb 2009, 18:30
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.