flat assembler
Message board for the users of flat assembler.

Index > Main > macro arg in strings?

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
is there some way for a macro arg to appear in a string eg
a macro f where

Code:
       f   xyz
    


is expanded to:

Code:
.a   db      'xyz'
      db 0
    


I tried:

Code:
macro f abc
     {
.a    db   '#abc#'
       db  0
     }
    


but when I tried "f xyz" it created in fact the string '#abc#'
and not 'xyz' Sad

I need this where I use a macro to define an entire function and
the function has a unique string used to know which invocation
of the macro was called,
Post 05 Jun 2007, 02:11
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 f arg
{
.a db `arg, 0
}    


However, things like "f a+b" will not work. To handle those situations as well you can use
Code:
macro f arg
{
label .a byte at $
  irps symbol, arg \{db \`symbol\}
  db 0
}    
Post 05 Jun 2007, 02:21
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
LocoDelAssembly wrote:
Code:
macro f arg
{
.a db `arg, 0
}    



that functions correctly Razz

Quote:

However, things like "f a+b" will not work. To handle those situations as well you can use
Code:
macro f arg
{
label .a byte at $
  irps symbol, arg \{db \`symbol\}
  db 0
}    

[/quote]

not completely sure what you mean,
can you give an example of using this and what the effect is?
Post 06 Jun 2007, 17:23
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
if you use the first one this happens:
Code:
; f a+b

.a db 'a'+b, 0    


Which will end up in a "Error: undefined symbol" due to the lack of "b" variable definition. Since obviously you don't want "b" to be handled as a variable instead of a string you have to iterate throughout all symbols and apply to them "`" separatelly because the "`" stops at the first symbol separator (a space or any of +-*/{}[]...).

With the second macro this is what happens:
Code:
;f a+b
label .a byte at $
db 'a'
db '+'
db 'b'
db 0    
Post 06 Jun 2007, 18:17
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.