flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > parallel definitions

Author
Thread Post new topic Reply to topic
rostok



Joined: 12 Feb 2022
Posts: 5
rostok
I want to give specific names to registers/names r1,r2,r3 etc. I have tried many codes but could not find a simple solution. The solution that I have finally found is something like

macro assign [x] {
common
rept 8 i:1 \{ define reg r\#i \}
forward
rept 1 j:reg \{
x equ r\#j
restore reg
\}

So the command
assign ah,vah

assigns ah to r8 and vah to r7. Is there a more simple solution? The complexity arises mostly from the restrictions of concetanation. It works only for parameters of macro like structures.
Post 12 Feb 2022, 07:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18487
Location: In your JS exploiting you and your system
revolution
Simpler IMO:
Code:
ah equ r8
vah equ r7    
Smile

But seriously, if you want to assign numeric things backwards then perhaps:
Code:
macro assign [reg] {
        common num equ 8
        forward
        reg equ r#num
        rept 1 n:num-1 \{num equ n\}
}
assign ah, vah    
[edit] Please ignore the code above, as pointed out in the next post, it is wrong!

It can be fixed like this:
Code:
macro assign [reg] {
        common num equ 8
        forward
        rept 1 n:num \{reg equ r\#n\}
        rept 1 n:num-1 \{num equ n\}
}
assign ah, vah    


Last edited by revolution on 12 Feb 2022, 11:52; edited 2 times in total
Post 12 Feb 2022, 08:03
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7992
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
Code:
        reg equ r#num    
This is unlikely to do what you intended, the concatenation operator is processed at the time of generating a line by macro, so it happens before EQU is recognized and processed.

A simple solution that comes to mind is to pre-fill a pool of register names and then use them. In this case the reverse order comes naturally as a consequence of stacking the names:
Code:
rept 8 i { define regpool r#i }
macro assign [reg] { match r, regpool \{ define reg r \} restore regpool }

assign ah, vah ; r8, r7    
Post 12 Feb 2022, 10:53
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 493
Location: Russia
macomics
Is it necessary to create implicit naming? Maybe it would be better to make an explicit assignment.
Code:
macro assign [def] { forward match name==reg,def \{ define reg name \} }
assign ah=r8, vah=r7    
Post 12 Feb 2022, 11:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18487
Location: In your JS exploiting you and your system
revolution
Tomasz Grysztar wrote:
revolution wrote:
Code:
        reg equ r#num    
This is unlikely to do what you intended, the concatenation operator is processed at the time of generating a line by macro, so it happens before EQU is recognized and processed.
Yes. That code is not correct.

I edited the post with the new line to replace it:
Code:
rept 1 n:num \{reg equ r\#n\}    
Post 12 Feb 2022, 11:54
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 115
Location: Marseille/France
sylware
I use "define my_local_reg_alias reg", then in classic macros (which can call other macros) to work with reg aliases (did not try calm), I go down to the definition of a reg, namely an "element", then I reconstruct the right register.
Maybe I am totally wrong though and there is an obvious other way to do that I did not see (as usual).
Post 12 Feb 2022, 15:18
View user's profile Send private message Reply with quote
rostok



Joined: 12 Feb 2022
Posts: 5
rostok
I have seen the code I wrote is wrong as rept parameter must accept numbers only. It is not the actual code of my solution.

My intention is to give arbitrary names to registers whenever I want. For example at the beginning of a routine, so I can use meaningful names for that routine. Giving explicit names is a good idea.

rept 8 i { define regpool r#i }
macro assign [reg] { match r, regpool \{ define reg r \} restore regpool }

assign ah, vah ; r8, r7


This solution is a bit shorter but not simpler than mine. I.e. it uses restore to assign a member of a list to the member of another list . I am a newbie of FASM and I am glad I found the only possible method. Thanks for the answers.
Post 13 Feb 2022, 07:04
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.