flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Trying to improve my syscall macro |
Author |
|
revolution 22 Apr 2017, 00:20
The # also has to be escaped with backslashes.
Code: if ~ reg eq p\#reg & ~ p\#reg eq |
|||
22 Apr 2017, 00:20 |
|
triplefault 22 Apr 2017, 01:33
revolution wrote: The # also has to be escaped with backslashes. Thank you, that solves one issue but now I'm getting "undefined symbol 'prdi'" even though it is one of the parameters of my macro. [Edit] Now that I know that I have to escape more than { and } in a macro within a macro, what other characters besides {, } and # need to be escaped? The manual only mentions { and }. [Edit 2] Ignore my last question, I was not searching the right way, I found the answer here. I have noticed that the if condition that successfully evaluates to true for only the defined parameters in my original code always evaluates to true even if the parameter is empty in my second attempt (after adding the backslashes to escape the #). Also sorry for editing so many times, I'm trying to find a solution and I update this with my new attempts and questions. For reference here's the new code with added backslashes: Code: macro syscall sysnum, prdi, prsi, prdx, pr10, pr8, pr9 { irps reg, rdi rsi rdx r10 r8 r9 \{ if ~ reg eq p\#reg & ~ p\#reg eq mov reg, p\#reg end if \} if ~ sysnum eq mov rax, sysnum end if syscall } |
|||
22 Apr 2017, 01:33 |
|
revolution 22 Apr 2017, 03:10
I see that your macro can never work that way. The outer macro replaces all instances of prdi it finds and then processes the inner code. Since the outer macro never finds prdi (it only sees p\#reg) then no parameter replacement happens.
Last edited by revolution on 22 Apr 2017, 04:49; edited 1 time in total |
|||
22 Apr 2017, 03:10 |
|
triplefault 22 Apr 2017, 04:46
You are right, I was expecting it to process the inner macro first but that would make no sense because it needs to process the outer macro first to realize that there is an inner macro. I'll continue using my first version of the macro that works well. Thank you for your help.
|
|||
22 Apr 2017, 04:46 |
|
l_inc 22 Apr 2017, 20:36
triplefault
If you need to enumerate multiple sequences of tokens pairwise, you can put one sequence into a stack of a symbol and then pop from that stack while enumerating tokens from another sequence: Code: macro syscall [arg*] { common local reg irps \reg, r9 r8 r10 rdx rsi rdi rax \{ define reg \reg \} forward if ~arg eq reg mov reg, arg end if restore reg common irpv _,reg \{ restore reg \} syscall } Here reg provides a stack and restore pops from it while the syscall arguments are being enumerated. This macro produces less unnecessary lines and catches more mistakes, but it is still error-prone in case some arguments are already partially in the listed registers. E.g., if the second macro argument is rax, its value will be overwritten by the syscall number before being put into rdi. That can be handled correctly, but the macro would become significantly more complex. P.S. It is a good idea to avoid overriding existing instructions and directives if not necessary. I.e., msyscall or xsyscall would be better names for the macro. _________________ Faith is a superposition of knowledge and fallacy |
|||
22 Apr 2017, 20:36 |
|
triplefault 23 Apr 2017, 03:57
l_inc: thank you for the recommendation and the code, I'll avoid overriding existing things in the future. Your solution works and it is what I wanted to do. This was just an exercise to practice writing macros so I don't worry about the potential problem of overwriting a register because in practice I'm more likely to avoid using a macro for this.
|
|||
23 Apr 2017, 03:57 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.