flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Define symbolic constants with sequential number in name

Author
Thread Post new topic Reply to topic
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?
Post 25 Dec 2020, 16:23
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7925
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
    \}
}    
Post 25 Dec 2020, 17:33
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Thanks!
Post 25 Dec 2020, 18:03
View user's profile Send private message Reply with quote
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
}    
Post 02 Jan 2021, 22:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
A simpler way would be to replace equ with dd, and delete the macro.
Post 02 Jan 2021, 22:41
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Laughing
All these equ's are generated by another macro.
So it's not a good idea Smile
Post 02 Jan 2021, 22:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
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
Post 02 Jan 2021, 22:48
View user's profile Send private message Visit poster's website Reply with quote
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 Smile
Post 02 Jan 2021, 23:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
The names are part of the dd.
Code:
name_1 dd 2.718281828    
Post 02 Jan 2021, 23:17
View user's profile Send private message Visit poster's website Reply with quote
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 Smile
Post 02 Jan 2021, 23:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
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    
Post 02 Jan 2021, 23:28
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 954
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.
Post 03 Jan 2021, 12:12
View user's profile Send private message Visit poster's website 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.