flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
bitRAKE 06 Apr 2009, 21:19
Doesn't the IF and END IF need to be in common blocks?
(They are evaluated at assembly stage, iirc.) |
|||
![]() |
|
buzzkill 06 Apr 2009, 21:36
Thanks bitRAKE, that was it: turns out there was a common somewhere above the "if"-line. So apparently common/forward/reverse create some kind of context, and if your "if" is in the common context, your "end if" must also be in a common context, I hadn't gotten that from reading the manual.
|
|||
![]() |
|
LocoDelAssembly 06 Apr 2009, 21:47
This is what's happen with your macro
Code: macro aMacro arg, [arg] { if ~ arg eq common local ofs ofs = 8 forward label arg at ebp+ofs ofs = ofs + 4 end if } aMacro one, two, three ; Assembler receives the following: if ~ one eq ofs?1 = 8 label two at ebp+ofs?1 ofs?1 = ofs?1 + 4 end if label three at ebp+ofs?1 ofs?1 = ofs?1 + 4 end if Note: "ofs?1" is a placeholder for the local symbol generated by the preprocessor, I don't remember now how the names are generated but is something like that. |
|||
![]() |
|
buzzkill 06 Apr 2009, 22:02
Is that the actual preprocessor-output? And if so, how did you get fasm to output that? But it looks kinda strange to me with the two "end if"s, I'm not sure how to interpret it. Was my explanation in the reply to bitRAKE correct, or not?
And just to be sure: my intention with the "if" was to check if [arg] isn't empty, ie at least one argument has been passed to the macro. So the "if" will only be executed once, right? |
|||
![]() |
|
bitRAKE 06 Apr 2009, 22:22
FORWARD/REVERSE copy the text block a number of times based on parameters.
COMMON copy the text block once. IF requires a matching END IF, so this limits usage. There is no context - MACRO is just text paste. ![]() buzzkill wrote: And just to be sure: my intention with the "if" was to check if [arg] isn't empty, ie at least one argument has been passed to the macro. So the "if" will only be executed once, right? |
|||
![]() |
|
LocoDelAssembly 06 Apr 2009, 22:33
Well, this is the output using the old FASMPRE tool:
Code: ;macro aMacro[arg] ;{ ; common ; if~arg eq ; common ; local ofs ; ofs=8 ; forward ; label arg at ebp+ofs ; ofs=ofs+4 ; end if ;} ;aMacro one,two,three,four if~one,two,three,four eq ; ofs?0000000 ofs?0000000=8 label one at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label two at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label three at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label four at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if Now the interesting part is that if I remove the first "common" then this happens: Code: ;macro aMacro[arg] ;{ ; if~arg eq ; common ; local ofs ; ofs=8 ; forward ; label arg at ebp+ofs ; ofs=ofs+4 ; end if ;} ;aMacro one,two,three,four if~one eq if~two eq if~three eq if~four eq ; ofs?0000000 ofs?0000000=8 label one at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label two at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label three at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if label four at ebp+ofs?0000000 ofs?0000000=ofs?0000000+4 end if Looks like the first "anonymous" block was a forward block. Note that you can also use the prepsrc debug tool also, but the problem with it is that you need a compilable source first while FASMPRE (unfortunately outdated) needs only a source that the preprocessor can handle with no syntax errors. Last edited by LocoDelAssembly on 06 Apr 2009, 22:40; edited 1 time in total |
|||
![]() |
|
buzzkill 06 Apr 2009, 22:39
Thanks for the explanation, guys. LocoDelAssembly: from what I read on the forum, fasmpre was only released for windows, so I can't use it. Maybe there will come an updated fasmpre for all platforms, because, as you say, prepsrc does you no good while you're still struggling to get your stuff compiled
![]() |
|||
![]() |
|
LocoDelAssembly 06 Apr 2009, 22:46
Oh didn't remember that. I now wonder if would be possible for fasm to still generate the fas file covering only up to the stage fasm completed successfully. Would that be possible or that would make the fas file unparseable?
BTW, I have edited my previous post because I was referencing the wrong parameter, now I changed to a macro with a single "vararg". |
|||
![]() |
|
buzzkill 06 Apr 2009, 23:42
LocoDelAssembly wrote: I now wonder if would be possible for fasm to still generate the fas file covering only up to the stage fasm completed successfully. Would that be possible or that would make the fas file unparseable? I don't think that would generate a valid fas file. But maybe there is a need for one tool to help with macros/preprocessing, seeing as I myself have in the past brought up the possibility of a fasm switch to print preprocessor output (-E a la gcc), you (and probably others) use fasmpre which is not available for all platforms and apparently outdated, and then there's prepsrc which only works on compilable sources. I know when I started messing with nasm macros, I used the preprocessor output a lot when I ran into trouble. |
|||
![]() |
|
Tomasz Grysztar 07 Apr 2009, 05:14
I considered to make fasm generate fas file even in case of error, as long as the preprocessor finished sucessfully - then fas would contain only the preprocessed source, and the other structures will be empty. I'm not sure if I'll get this for 1.68, though.
|
|||
![]() |
|
buzzkill 07 Apr 2009, 22:59
Tomasz Grysztar wrote: I considered to make fasm generate fas file even in case of error, as long as the preprocessor finished sucessfully - then fas would contain only the preprocessed source, and the other structures will be empty. I'm not sure if I'll get this for 1.68, though. No hurry Tomasz, it's not a priority of course, but I think it could be a valuable help for people who are learning fasm preprocessor (which is more elaborate then other assembler's I've used). |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.