flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > doif macro with curly bracket |
Author |
|
revolution 11 Nov 2023, 14:12
Use =
Code: z = 1 Otherwise if your constants are not variables but are defines (or equ) then use match. |
|||
11 Nov 2023, 14:12 |
|
Jin X 11 Nov 2023, 14:38
revolution wrote: Use = I didn't understand the second part of your answer :-/ What curly brackets should I remove? How to detect { char in the end of macro parameter? This works (with fixed rept parameter): Code: macro doif cond* { local @cond @cond equ cond match a \\{, cond \{ @cond equ a display 'yes!',10 \} if @cond display 'true' else display 'false' end if rept 1 \{ } doif 1 = 1 \\{ ret } |
|||
11 Nov 2023, 14:38 |
|
revolution 11 Nov 2023, 14:49
Maybe like this.
Code: macro doif val0, val1 { match =val0,val1 } doif 0,1 { display '-',10 } doif 1,1 { display '+',10 } |
|||
11 Nov 2023, 14:49 |
|
Jin X 11 Nov 2023, 15:28
revolution wrote: Maybe like this. Code: @if x and y > z { ... } @elif x and y = z & b { ... } @else { ... } |
|||
11 Nov 2023, 15:28 |
|
revolution 11 Nov 2023, 22:30
What are x, y and z? Are they assembler variables assigned with =? If they are then what you want to do is impossible. The preprocessor has no insight into the values of assembler time variables.
|
|||
11 Nov 2023, 22:30 |
|
revolution 12 Nov 2023, 02:36
To show the problem, consider the simplest case.
Code: x = 5 rept x { display '.' } Code: flat assembler version 1.73.31 (16384 kilobytes memory) test.asm [2]: rept x { display '.' } error: invalid value. Compare to: Code: x equ 5 rept x { display '.' } Code: flat assembler version 1.73.31 (16384 kilobytes memory) ..... 1 passes, 0 bytes. Now note the problem with this type of approach: Code: x equ 5 x = 3 Code: flat assembler version 1.73.31 (16384 kilobytes memory) test.asm [2]: x = 3 processed: 5=3 error: reserved word used as symbol. |
|||
12 Nov 2023, 02:36 |
|
Jin X 12 Nov 2023, 11:19
I know about this but I'm looking for some hack
Maybe some assembling-time construction that can take assembler variable. Or some macro-if-equ-match-smthelse combination that will help to allow to achieve the goal |
|||
12 Nov 2023, 11:19 |
|
revolution 12 Nov 2023, 11:22
Please specify whether x, y and z are assembler variables or preprocessor defines.
That makes a difference to the code you can write. |
|||
12 Nov 2023, 11:22 |
|
Jin X 12 Nov 2023, 11:57
revolution wrote: Please specify whether x, y and z are assembler variables or preprocessor defines. |
|||
12 Nov 2023, 11:57 |
|
revolution 12 Nov 2023, 12:04
I mentioned above with assembler variables you can't mix them with curly brackets. So if you want x, y, and z to be "anything" then it can't ever work.
I you really need to use curly brackets, for some reason, then you have to use preprocessor defines. These are the rules of fasm and how it works internally. If you remove your criterion for curly brackets then using if/else/end if will work perfectly fine for almost all circumstances. It is more flexible and more clear about what it is doing. |
|||
12 Nov 2023, 12:04 |
|
AsmGuru62 12 Nov 2023, 13:26
I also did not get the part why the standard FASM constructs are to be replaced by {}.
If typing the .endif or .elseif is a little annoying -- and I can accept that as a fact -- it annoyed me too. Until I started to use a better text editor (or find an IDE), which allows to insert the prepared code fragments. There are some nice fragments to use in FASM. IF() statements: Code:
.if ()
.endif
Code: .if (CARRY?) .endif Full IF() statement: Code:
.if ()
.else
.endif
switch() statement: Code: .if () .elseif () .elseif () .elseif () .else .endif Loops of all kinds: Code: .repeat sub ecx, 1 .until (ZERO?) Code: .while (ecx) sub ecx, 1 .endw A function: Code: proc NONAME uses reg reg reg, param, param, param local loc1:DWORD ret endp Once your IDE or editor is set up with fragments -- you can insert those with just a few mouse clicks. |
|||
12 Nov 2023, 13:26 |
|
Overclick 12 Nov 2023, 14:13
Maybe this topic will help
https://board.flatassembler.net/topic.php?t=22423 |
|||
12 Nov 2023, 14:13 |
|
revolution 12 Nov 2023, 14:30
To those advocating .if and the like, please note that those are very different from if.
The .if macro variants place code into the output that evaluates things at runtime. The if native assembler construct evaluates things at assembly time and omits code from the output. So they are not the same, and are not replacements for each other. The OP was describing constructs similar to if. |
|||
12 Nov 2023, 14:30 |
|
AsmGuru62 12 Nov 2023, 17:03
I see. Indeed, the conditional assembly would use "if" and "end if", but my point was why replace those with a "{", "}"?
Just because typing those will be too time consuming or is there a "beauty of code" involved somehow? The good editor or IDE will help with that in the same way I described. |
|||
12 Nov 2023, 17:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.