flat assembler
Message board for the users of flat assembler.

Index > Linux > How does "common" work in macro?

Author
Thread Post new topic Reply to topic
ntos



Joined: 06 Jul 2023
Posts: 18
ntos 07 Jul 2023, 22:17
Hi,
Here is some code I copied from https://gpfault.net/posts/asm-tut-1.txt.html

Code:
macro foo a, [b, c] {
        common ; we'll explain what "common" means later
                db a, b
                db a, c
        }
        foo 0, 1, 2, 3, 4
    

This is equivalent to:
Code:
        db 0, 1, 3
        db 0, 2, 4
    


Can you explain how foo 0,1,2,3,4 could become db 0,1,3? I think it must be db 0,1 and db 0, 2.
Thank you very much.
Post 07 Jul 2023, 22:17
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 909
Location: Russia
macomics 07 Jul 2023, 23:18
1) Comparison of formal and actual parameters: foo a=0, b=1, c=2, b=3, c=4 (or a=0, b=<[0]=1, [1]=3>, c=<[0]=2, [1]=4>)
2) Substitution of formal parameters: db a=0, b=<[0]=1, [1]=3>
db a=0, c=<[0]=2, [1]=4>
3) The list is expanded by the db directive and the sequence is obtained: db 0, 1, 3, 0, 2, 4
4) When using forward or reverse directives, instead of parameters b and c, not lists will be substituted, but a single value with the corresponding index from the list: forward db a, b, c => db a=0, b[0]=1, c[0]=2 => db a=0, b[1]=3, c[1]=4
Post 07 Jul 2023, 23:18
View user's profile Send private message Reply with quote
ntos



Joined: 06 Jul 2023
Posts: 18
ntos 08 Jul 2023, 04:54
Thank you very much for your clear answer. The fasm manual must be updated with this answer.
Post 08 Jul 2023, 04:54
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.