flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Question: Conversion to string constant

Author
Thread Post new topic Reply to topic
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 16 Mar 2010, 18:08
Hello.

Could somebody tell, how to convert macro argument into string.
Suppose I have a macro ToStr which accepts two arguments - one is symchain, another is result. When I call this macro with symchain equal to A+B, I need to receive string constant 'A+B' in result (so I could display it for example, or use with db directive). I tried ` sign, but i converts to string only A symbol.

Thank you.
Post 16 Mar 2010, 18:08
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 16 Mar 2010, 19:14
Siberian,

Backtick converts only one following token to string. You need to irps over symbols in symchain.
Code:
struc reequ [arg] {
common
  restore .
  . equ arg
}
struc equ" [arg] {
common
  . equ ""
  irps s, arg \{
    match v,.\\#\\`s \\{
      . reequ v
    \\}
  \}
}
a equ" ! \\\# $ % & ( ) * + , - . / : < = > ? @ [ ] ^ _ \\\` \\\{ | \\\} ~
db a    
There are several restrictions on tokens in the list to iterate through, though. Lone backslash, single/double quotes and semicolon simply don't live long enough to get preprocessed. Macro operators and braces can be backslashed as usual, but this depends on dynamic macro nesting level.


Last edited by baldr on 16 Mar 2010, 19:19; edited 1 time in total
Post 16 Mar 2010, 19:14
View user's profile Send private message Reply with quote
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 16 Mar 2010, 19:17
Already found the way myself.
Post 16 Mar 2010, 19:17
View user's profile Send private message Reply with quote
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 16 Mar 2010, 19:24
Thank you baldr. I knew about irps, but just didn't realize that concatenating two string constants with # sign will produce new string constant. I tried several things, but couldn't find a solution, so I posted a message and went to a shower. While being there, I got an idea to try this concatenation, and it worked. The same time, you posted a reply, so you just reassured me that this is the right way. One thing bothers me though. This reequ structure is it really necessary?
Post 16 Mar 2010, 19:24
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 16 Mar 2010, 20:02
Siberian,

reequ is an utility macro: it replaces current value of symbolic constant.
Code:
mov     equ     "hello"
mov     reequ   "world"
restore mov
; Now «mov» is not a symbolic constant    
Post 16 Mar 2010, 20:02
View user's profile Send private message Reply with quote
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 16 Mar 2010, 20:06
So then we also need utility macros for struc and for macro directives?
Post 16 Mar 2010, 20:06
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 16 Mar 2010, 20:26
Siberian,

I've used struc-macro because that way reequ will look like equ directive. There are differences though, due to macro operators.

struc and macro are reserved words, they can't be used as a macro name. Wink
Post 16 Mar 2010, 20:26
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.