flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Can't get % to work

Author
Thread Post new topic Reply to topic
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
I can't % to work. It seems like it is not replaced by the corresponding number. What is wrong?

Code:
macro hashtable_define2 hashtable, size {
        repeat size
            list_define hashlist_#hashtable%
        end repeat
}    

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 19 Aug 2009, 19:31
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You'll need to do the following change:
Code:
macro hashtable_define2 hashtable, size {
        rept size i\{
            list_define hashlist_#hashtable\#i
        \}
}    


% is available in assembler stage but you need to create symbols so you need preprocessor stage.
Post 19 Aug 2009, 19:39
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Ok, thanks.

Another question: how can I check whether a macro parameter was passed or not (I think I want assembly stage here)?
Post 19 Aug 2009, 19:43
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
macro wasPassed arg
{
local passed

  passed equ

  match any, arg
  \{
    display "Something was passed!", 13, 10
    passed equ 1
  \}

  match ,passed
  \{
    display "Nothing was passed...", 13, 10
  \}
}

; Tests
wasPassed alfa-beta-gamma
wasPassed    
Post 19 Aug 2009, 19:52
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Thank you!
Post 20 Aug 2009, 08:43
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Is there any reason why I can't use match ,arg directly (instead of using passed)?
Post 20 Aug 2009, 09:49
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
No reason, my answer simulated an "If passed/Else" instead of an "If passed/If not passed" Razz
Post 20 Aug 2009, 18:41
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Is it not possible to create a new macro inside a macro?

Code:
macro hashtable_define table, size {
        if (size and (size-1)) <> 0
            __ error: size must be a power of 2
        end if
        
        macro hash_#table reg \{    ; doesn't seem to work
                and reg, size - 1
        \}
}    
Post 21 Aug 2009, 09:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
Works for me:
Code:
macro hashtable_define table, size {
        if (size and (size-1)) <> 0
            __ error: size must be a power of 2
        end if
        
        macro hash_#table reg \{
                and reg, size - 1
        \}
}

hashtable_define testing,8
hash_testing eax    
Post 21 Aug 2009, 09:29
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Thanks for testing it. It seems like it won't work when the invokation of hashtable_define is placed after the invokation of hash_testing.
Post 21 Aug 2009, 18:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
Plue wrote:
Thanks for testing it. It seems like it won't work when the invokation of hashtable_define is placed after the invokation of hash_testing.
In fasm the preprocessor is not multi-pass. You have to define things before you can use them. Only the assembler is multi-pass.
Post 21 Aug 2009, 22:29
View user's profile Send private message Visit poster's website 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. Also on YouTube, Twitter.

Website powered by rwasa.