flat assembler
Message board for the users of flat assembler.

Index > Main > Constants within macros

Author
Thread Post new topic Reply to topic
pini



Joined: 04 Jul 2005
Posts: 14
pini 27 Jul 2005, 16:30
Is it possible to export constants (symbolic or not) from within a macro, with name taken from parameters ?
For example, if I define something like this:
Code:
my_macro constant_name, constant_value
{
; Do stuff here
constant_name = constant_value ;or whatever computation
; Do stuff here
}    

A call to 'my_macro MY_CONSTANT, 0x100' is meant to extend to someting like MY_CONSTANT = 0x100, so that MY_CONSTANT is available elsewhere in the code.

I know the above syntax is wrong, but you get the idea. If it's possible, I'd really like to know how.

Thanks is advance.

pini[/img]
Post 27 Jul 2005, 16:30
View user's profile Send private message Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank 27 Jul 2005, 17:42
It is possible, see the example below.

Code:
; Declare two macros
macro my_numeric constant_name, constant_value
{ constant_name = constant_value }

macro my_symbolic constant_name, constant_value
{ constant_name equ constant_value }

; Apply the macros
my_numeric A_NUMERIC, 0x100
my_symbolic A_SYMBOLIC, SomeString

; Test the results
if (defined A_NUMERIC)
  display 'A_NUMERIC is defined',13,10
end if

if (A_NUMERIC = 100h)
  display 'A_NUMERIC equals 100h',13,10
end if

if (defined A_SYMBOLIC)
  display 'A_SYMBOLIC is defined',13,10
end if

if (A_SYMBOLIC eq SomeString)
  display 'A_SYMBOLIC equals SomeString',13,10
end if
    


Note that the output differs slightly for numerical constants versus symbolic constants:

Code:
A_NUMERIC is defined
A_NUMERIC equals 100h
A_SYMBOLIC equals SomeString
    


Regards

Frank
Post 27 Jul 2005, 17:42
View user's profile Send private message Reply with quote
pini



Joined: 04 Jul 2005
Posts: 14
pini 27 Jul 2005, 20:15
You're right, it works ! I don't know what I did wrong when I tested it, anyway it doesn't really matter Smile

Thanks a lot

pini
Post 27 Jul 2005, 20:15
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.