flat assembler
Message board for the users of flat assembler.

 Index > Linux > How does "common" work in macro?
Author
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.
07 Jul 2023, 22:17
macomics

Joined: 26 Jan 2021
Posts: 913
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
07 Jul 2023, 23:18
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.
08 Jul 2023, 04:54
 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