flat assembler
Message board for the users of flat assembler.
Index
> Main > please explain this macro behavior, looks wrong to me |
Author |
|
revolution 11 Dec 2014, 02:59
Use equals (=) instead of equ.
Code: value = 42 |
|||
11 Dec 2014, 02:59 |
|
tthsqe 11 Dec 2014, 03:15
Ah, thanks. I ended up using equ because value was used in another macro, and fasm didn't like = in the case. Ill try to switch from preprocessor to assembler in that macro and see if I can fix it.
|
|||
11 Dec 2014, 03:15 |
|
tthsqe 11 Dec 2014, 03:16
but then the match should handle the conditional p eprocessing correctly, no?
|
|||
11 Dec 2014, 03:16 |
|
revolution 11 Dec 2014, 03:28
Don't use "color" as a local and it should be fine.
|
|||
11 Dec 2014, 03:28 |
|
tthsqe 11 Dec 2014, 03:36
ah, don't know what I was thinking with local color. This seem to be working. For a moment I though you couldn't work with conditional defintions of local variables
Code: White fix 0 Black fix 1 macro move a,b { if b eq 42 mov a, 42 else if b eq 24 mov [a], dword 24 else err end if } macro testing color { local value match =White,color \{ value equ 42 \} match =Black,color \{ value equ 24 \} move eax, value } Start: testing Black testing White |
|||
11 Dec 2014, 03:36 |
|
baldr 13 Dec 2014, 22:30
tthsqe,
Had you intentionally used symbolic comparison (eq) instead of numeric (=) in if conditions? |
|||
13 Dec 2014, 22:30 |
|
tthsqe 14 Dec 2014, 09:28
After reading the docs, it was my impression that something like the conditional in "if A = B" is invisible to the preprocessor and is dealt with by the assembler. Something like "if A eq B" is handled as expected by the precoressor. Is there something done wrong in the last example I posted?
After thinking about this more, it looks like the preprocessor is limited in fasm with respect to expression evaluation. For example, something like Code: macro bar c { if c eq 8 mov eax, 8 else err end if } macro foo a, b { bar a+b } foo 5,3 ; 5+3 is passed to bar and is not "eq" to 8, so err is encountered I realize that "if c = 8" will make this work witht he assembler, but what if I want to keep using the preprocessor? |
|||
14 Dec 2014, 09:28 |
|
evk1 14 Dec 2014, 10:52
tthsqe wrote: Something like "if A eq B" is handled as expected by the precoressor. Are you sure? After reading docs I came to the opposite conclusion. To my mind, the preprocessor just replaces symbolic constants with their values in expressions like if A eq B, while equality check is performed by the assembler. For example following code displays only expr1 is true. Code: a equ xyz expr1 equ a eq xyz define expr2 a eq xyz if expr1 display 'expr1 is true' end if if expr2 display 'expr2 is true' end if Don't I understand something? _________________ Sorry for my English |
|||
14 Dec 2014, 10:52 |
|
baldr 14 Dec 2014, 16:53
tthsqe & evk1,
Condition in if directive is definitely evaluated during assembly stage. I'd meant that eq operator straightforwardly compares its operands for being exactly equal (i.e. same parsed symbols in the same order, even if those operands are nonsensical for numeric comparison): Code: if Hello, tbyte ! eq Hello, tword ! display "eq" else display "~eq" end if evk1, your example with define works as defined. You may use match directive to expand symbolic constants in defined symbolic constants' values though (one step at a time): Code: define A xyz define B A; B eq A, not xyz define C B; C eq B, not xyz or A macro define_@ {; allow recursion macro @ [$*] \{; expand tail and use the result as a statement define_@ match \\$, $ \\{ \\$ \\} purge @ \} } define_@ if A eq xyz display "A eq xyz (direct expansion)", 13, 10 end if if B eq xyz; expands to 'if A eq xyz' display "B eq xyz (direct expansion)", 13, 10 @ else if B eq xyz; expand 'if A eq xyz' once display "B eq xyz (indirection level 1)", 13, 10 end if if C eq xyz; expands to 'if B eq xyz' display "C eq xyz (direct expansion)", 13, 10 @ else if C eq xyz; expand once to 'if A eq xyz' display "C eq xyz (indirection level 1)", 13, 10 @ @ else if C eq xyz; expand twice display "C eq xyz (indirection level 2)", 13, 10 end if |
|||
14 Dec 2014, 16:53 |
|
evk1 14 Dec 2014, 17:13
baldr wrote: evk1, your example with define works as defined. You may use match directive to expand symbolic constants in defined symbolic constants' values though (one step at a time Thank you, but I had already known it. My goal was to demonstrate eq cannot expand symbolic constant by itself. _________________ Sorry for my English |
|||
14 Dec 2014, 17:13 |
|
baldr 14 Dec 2014, 17:21
evk1,
eq is an operator of assembly stage directive if, how could it expand anything? |
|||
14 Dec 2014, 17:21 |
|
evk1 14 Dec 2014, 17:55
baldr wrote: evk1, Of course, it can't. And this was the main idea of my post. I thought, it was clear. Oh, most of my posts was misunderstood or just ignored. Is my English really so dreadful? Oh, moderators, sorry for so many off-topic replies. _________________ Sorry for my English |
|||
14 Dec 2014, 17:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.