flat assembler
Message board for the users of flat assembler.

 Index > Main > Constants within macros
Author
pini

Joined: 04 Jul 2005
Posts: 14
pini
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.

pini[/img]
27 Jul 2005, 16:30
Frank

Joined: 17 Jun 2003
Posts: 100
Frank
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
27 Jul 2005, 17:42
pini

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

Thanks a lot

pini
27 Jul 2005, 20:15
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum