flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > The "#" on constants names

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Aug 2005, 01:45
Why this works
Code:
macro m{
  constant#1 = "H"
}m
display constant1, 13, 10    
and this don't work
Code:
constant#1 = "H"
display constant1, 13, 10    
?

I'm trying to find a way of generate constants name attaching a number like this:
Code:
macro attach [names]{
common
  num = 1
forward
  names#num = 0
  num = num + 1
}    


Of course that code doesn't work, it's only to show what I want, if I do "attach var", I want "var1 = 0" to be defined instead of "varnum = 0".

Please help Sad
Post 16 Aug 2005, 01:45
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 16 Aug 2005, 02:34
Quote:

Why this works
Code:
macro m{ 
  constant#1 = "H" 
}m

display constant1, 13, 10
    

and this don't work
Code:
constant#1 = "H" 
display constant1, 13, 10
    

?


*calls Tomasz* What's up with THIS?
Post 16 Aug 2005, 02:34
View user's profile Send private message AIM Address Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 16 Aug 2005, 03:12
The '#' only works inside macros (including rept and irp). For your case you will need to use the preprocessor 'rept' to make the labels. Perhaps something like this.
Code:
rept 10 count {names#count=0}    
Label names can only be defined during the preprocessor stage. Once the assembly stage has begun only the values of the labes can be changed.
Post 16 Aug 2005, 03:12
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Aug 2005, 15:23
Actually every name will have only one number, for example if I do "attach foo, bar", I'm specting foo1 and bar2 to be defined anymore.

Well I think with your help I will be able to do that now, thank you! Very Happy
Post 16 Aug 2005, 15:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 16 Aug 2005, 16:54
You need to put a double hash, one hash for each level of macro:
Code:
macro attach [names]{
forward
  rept 10 count \{names##count=0\} ;<--- two hashes here
}

attach foo, bar

;display foo+'0', 13, 10           ; Doesn't work
display foo1+'0', 13, 10           ; Works
display bar10+'0', 13, 10          ; Works
;display names5+'0', 13, 10        ; Doesn't work

rept 10 count {constant#count=0}

display constant7+'0', 13, 10      ; Works    
Post 16 Aug 2005, 16:54
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Aug 2005, 16:59
No, wait, it doesn't work either Sad
Code:
macro attach [names]{
forward
  rept 10 count \{names#count=0\}
}

attach foo, bar

display foo+'0', 13, 10            ; Doesn't work
display foo1+'0', 13, 10           ; Doesn't work
display bar10+'0', 13, 10          ; Doesn't work
display names5+'0', 13, 10         ; Doesn't work

rept 10 count {constant#count=0}

display constant7+'0', 13, 10      ; Works    
Post 16 Aug 2005, 16:59
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 16 Aug 2005, 17:02
Actually according to the current manuals, you should use backslashes to escape the hash as many times as you need, as with any other macro-specific operators. The multiple hashes are kept for backward compatibility, but are no longer documented officially. Wink
Post 16 Aug 2005, 17:02
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Aug 2005, 17:33
Code:
macro attach [names]{
forward
  rept 10 count \{names \# count=count\}
}    


Thanks Tomasz Very Happy
Post 16 Aug 2005, 17:33
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Aug 2005, 23:07
Well, after hours of tries I'm still having problems doing this Sad

I need a macro which do the following:
Code:
someMacro 1, 5, 7, 10.5

;At this point I want these numerical constants (not equates) defined and with these values
;value1 = 1
;value2 = 5
;value3 = 7
;value4 = 10.5    


I can't find a way to do that Sad
Post 16 Aug 2005, 23:07
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 16 Aug 2005, 23:56
Code:
        irps count, 1 2 3 4 5 6 7 8 9 10
         { foo # count = count }     
Post 16 Aug 2005, 23:56
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Aug 2005, 00:36
Reverend, it doesn't works either. I need every constant with the values passed to the macro, not "fooX = X".

Another example:
Code:
someMacro 10, 7.2, aConstant

; At this point I need EXACTLY these constants defined with those values:

;foo1 = 10
;foo2 = 7.2
if foo3 = aConstant
  display "OK, the macro works!!",13,10
end if    
I need something like "foo # paramNumber = paramValue", where foo is always "foo", paramNumber goes from 1 to 3 and paramValue 10, 7.2, aConstant when I call the macro with this "someMacro 10, 7.2, aConstant".
Post 17 Aug 2005, 00:36
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 17 Aug 2005, 01:06
oh, btw you mean:
if foo3 eq aConstant
not
if foo3 = aConstant
cause it woudn't be valid, = is for assigning constants.

_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 17 Aug 2005, 01:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Aug 2005, 01:11
UCM, "if foo3 = aConstant" is valid, check it with this if you want:
Code:
foo = 4
bar = 5

if foo = bar
  display "foo = 5",13,10
end if
bar = bar - 1
if foo = bar
  display "foo = 4",13,10
end if    
BTW, aConstant is a numerical constant like the others.
Post 17 Aug 2005, 01:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 17 Aug 2005, 01:18
Code:
macro bar name,[count,value] {forward name#count=value}
bar foo,1,1,2,5,3,7,4,10
bar foo,1,10,2,7.2,3,aConstant    
BUt I think you want automatic numbering? I'm not sure if it is possible to get the numbering automatic, perhaps it is but I can't see how. But the above macro will do the job for you if you put the numbering manually.
Post 17 Aug 2005, 01:18
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Aug 2005, 01:48
revolution wrote:
BUt I think you want automatic numbering?
Yes, you are right, I need automatic and always from 1 to count. Thanks for post that code, I didn't know that the macros with [x,y] were possible.
Post 17 Aug 2005, 01:48
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 17 Aug 2005, 02:09
Oh, well maybe I'm getting rather mixed up.

_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 17 Aug 2005, 02:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 17 Aug 2005, 09:42
One of possible solutions is:
Code:
macro someMacro [val]
 { common
    counter equ 1
   forward
    match current,counter ; this we need to get value of counter before preprocessing
    \{
       value \# current = val
       rept 2 i:current \\{ counter equ i \\} ; this increases the counter
    \}
 }

someMacro 1,5,7,10.5 ; it defines value1=1, value2=5, etc.    
Post 17 Aug 2005, 09:42
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 17 Aug 2005, 10:01
On a side-topic about constants:
Is there a way to visually unpack bits and FASM still generates:
Code:
mov eax,1000 0000b
    

Of course FASM gives error here, but what can delete the extra spaces for FASM to assemble?
Post 17 Aug 2005, 10:01
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Aug 2005, 11:27
Surprised Excelent Tomasz, thank you!!!

Just another question, why only works with "rept 2"? I can't see why is needed repeat 2 times "counter equ i".
[edit]I know now, the first time "counter EQU i" and the second time "counter EQU (i+1)", sorry Embarassed[/edit]
Post 17 Aug 2005, 11:27
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Aug 2005, 19:12
grrr, i was going to make same solution as privalov but i forgot to escape # operator... grrr, i could have been first Smile))
Post 17 Aug 2005, 19:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.