flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Define symbolic constants with sequential number in name
Author
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Hello.
I want to create a macro that will define symbolic constants with sequential number in name.

E.g. 'macro def val' should define '_var0' at the 1st time, '_var1' the next time, then '_var2', '_var3', etc...

How can I concat name and number?
25 Dec 2020, 16:23
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7960
Location: Kraków, Poland
Tomasz Grysztar
Code:
```define DEFCNT 0

macro def val
{
rept 1 current:DEFCNT, next:DEFCNT+1
\{
define _var\#current val
define DEFCNT next
\}
}    ```
25 Dec 2020, 17:33
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Thanks!
25 Dec 2020, 18:03
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Is there more simple way for access to complex names than this 3-level rept-structure?
Code:
```cur_set equ 0
const0_num equ 3
const0_val0 equ 1.0
const0_val1 equ 1.5
const0_val2 equ 3.14

macro def
{
rept 1 set:cur_set \{
rept const\#set\#_num % \\{
rept 1 n:%-1 \\\{  ; to start from 0
dd const\\\#set\\\#_val\\\#n
\\\} ; rept
\\} ; rept
\} ; rept
}    ```
02 Jan 2021, 22:38
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18266
Location: In your JS exploiting you and your system
revolution
A simpler way would be to replace equ with dd, and delete the macro.
02 Jan 2021, 22:41
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X

All these equ's are generated by another macro.
So it's not a good idea
02 Jan 2021, 22:46
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18266
Location: In your JS exploiting you and your system
revolution
Instead of equ use dd. I was serious. Don't generate equates in the macro. Build a macro that places dd.

ETA: See here for building lists:
https://board.flatassembler.net/topic.php?t=12012
02 Jan 2021, 22:48
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
I want to declare aliases (names) for numbers.
I will refer to them by names in macro A and define (place to code) in macro B.
So I need names anyway, I can't just place dd without names...

Moreover I need arrays of numbers
02 Jan 2021, 23:09
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18266
Location: In your JS exploiting you and your system
revolution
The names are part of the dd.
Code:
`name_1 dd 2.718281828    `
02 Jan 2021, 23:17
Jin X

Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
I know but I need to generate these names...
E.g. I want to be able to use both numeric and symbolic names (just 7.0 or seven), so I need prefixes (for numbers).
And I want to be able to use the same names for different arrays.

But I'll thinks about simplification of this, thanks
02 Jan 2021, 23:24
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18266
Location: In your JS exploiting you and your system
revolution
You can't use numeric values as names:
Code:
`name_4e-3 equ 4e-3 ; this can't work    `
02 Jan 2021, 23:28
DimonSoft

Joined: 03 Mar 2010
Posts: 960
Location: Belarus
DimonSoft
I guess, a valid reason to avoid simply generating dd instead of equ’s is to be able to push such values as immediates with stdcall-like calling conventions. Referring to data in memory is less efficient in such cases, so, having both (if used for dd declarations) might have sense.
03 Jan 2021, 12:12
 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