flat assembler
Message board for the users of flat assembler.
Index
> Main > How can I use parameters with "define"? Goto page 1, 2 Next |
Author |
|
revolution 21 Mar 2010, 14:34
You can't. fasm does not support inline macros.
|
|||
21 Mar 2010, 14:34 |
|
Fanael 21 Mar 2010, 15:05
Code: macro mov first*, second* { local done define done 0 match =multiply =( x =, y =), second \{ mov first, x * y define done 1 \} match =0, done \{ mov first, second \} } mov eax, <multiply(2, 7)> I know that it's doesn't and it's not possible to make it work as OP wants to |
|||
21 Mar 2010, 15:05 |
|
lieyan2024 21 Mar 2010, 16:15
Thanks revolution, you let me know the limit of FASM.
Thanks Fanael, you gave me a resolution of the example. But "inline macro" is powerful utility, why does not FASM support it? |
|||
21 Mar 2010, 16:15 |
|
hopcode 21 Mar 2010, 17:05
revolution wrote: You can't. fasm does not support inline macros. Yes...and no: have you ever seen this ? Code: macro @multiply X,Y {@multiply equ X*Y } @multiply 7,3 display_decimal @multiply mov eax,@multiply ;<--------- 15h @multiply 8,2 display_decimal @multiply mov eax,@multiply ;<--------- 10h It seems a PURGE after an EQU. All symbols and directive are equals, but some of them more "assembling stage" than other symbols. Cheers, hopcode _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
21 Mar 2010, 17:05 |
|
revolution 21 Mar 2010, 17:11
hopcode wrote: It seems a PURGE after an EQU. All symbols and directive are equals, BTW: You might want to consider putting brackets around X*Y Code: macro @multiply X,Y {@multiply equ (X*Y) } Code: macro @multiply X,Y {@multiply = X*Y } Last edited by revolution on 21 Mar 2010, 17:33; edited 1 time in total |
|||
21 Mar 2010, 17:11 |
|
hopcode 21 Mar 2010, 17:29
revolution wrote: Restore is to undo EQUs... But to me it sounds strange every of the above behaviours apart this one, because inside macro it is not possible purging the symbol, also a temporairly EQU before exiting the macro is still ok in the scope. Code: macro @multiply X,Y { @multiply equ mov eax,(X*Y) @multiply } @multiply 7,3 ;-----ok @multiply 8,2 ;-----ok _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
21 Mar 2010, 17:29 |
|
revolution 21 Mar 2010, 17:32
hopcode wrote: ... because inside macro it is not possible purging the symbol ... |
|||
21 Mar 2010, 17:32 |
|
bitshifter 21 Mar 2010, 17:50
Why make life so difficult?
Code: mov eax,124*200 |
|||
21 Mar 2010, 17:50 |
|
hopcode 21 Mar 2010, 17:54
I mean that this is strange that such code works
Code: macro @multiply X,Y {@multiply = X*Y } ...Or i mistake, it is to say, "=" works external ok like purge, but not in the macro scope (as it is by design, during macro definition). The question is: even if in the scope of it i have redefined it @multiply = Y+X , it remains always a macro, and i can use it again ? ... must go now, hear you later Cheers, hopcode _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
21 Mar 2010, 17:54 |
|
revolution 21 Mar 2010, 18:06
The macro address space is separate from the variable address space. You can have this:
Code: @m = 4 macro @m v {db v} @m @m |
|||
21 Mar 2010, 18:06 |
|
hopcode 21 Mar 2010, 21:46
Apart the fact that bitshifter has the best solution,imho
revolution wrote: macro address space is separate from the variable address space. Code: ;----but it doesnt work "reserved word used as symbol". macro @m v {db v} ;<--- @m @m @m = 90h But this is ok Code: macro @m v {db v} ;--- definition @m n n = 90h Now, i'll try to explain it simple. Please,correct the text if needed. Macro-name definitions (and their internal-implement too, see the following case) have priority on all other assignments-type: equ,define,= I have not tested it with fix, because iirc it is somehow "deprecated". For example the "bold" assignment @m = 90h has low priority (a lower stack position i imagine) after the definition of a macro under the same name "@m"; that assignment is, as you know, an assembling-stage assigment, while macro definition and implementation happens already in a pre-procedural stage. For this reason you have (all thorough the code) working code like the following Code: macro @multiply X,Y { define @multiply mov eax,(X*Y) @multiply define @multiply (X*Y) } @multiply 7,3 mov ecx,@multiply @multiply 8,2 mov ecx,@multiply restore @multiply restore @multiply mov edx,@multiply ;00403000 B8 15000000 MOV EAX,15h ;00403005 B9 15000000 MOV ECX,15h ;0040300A B8 10000000 MOV EAX,10h ;0040300F B9 10000000 MOV ECX,10h ;00403014 BA 15000000 MOV EDX,15h without using an external way to do it. Internally, (under the scope of the macro) fasm let you define/do/"execute" a name even if this name appears to be the macro-name definition Code: define @multiply mov eax,(X*Y) @multiply Now,... will this wonderful feature be changed in the future ? Cheers, hopcode _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
21 Mar 2010, 21:46 |
|
edfed 21 Mar 2010, 21:51
lieyan2024 wrote: I want to write below code in FASM: maybe asm and C are not the same. c is abstract, asm is real. when coding in asm, you should forget averything about C, and think around a machine, named CPU. a pure mechanical machine that does things around binary datas in a memory that is at real locations. then, you should know what a CPU is and does for real. |
|||
21 Mar 2010, 21:51 |
|
lieyan2024 22 Mar 2010, 02:40
Thanks edfed, I know FASM is a very simple assembler, we must make more effort than in high-level programming languages.
I like this! So I want to implement "rva" by myself. "rva" in FASM is an operator, I can use it like below: mov eax, rva STRING_TABLE Look, "rva" performs like a "inline macro". I think other guys maybe want to do the same thing, this is why I submitted this subject. |
|||
22 Mar 2010, 02:40 |
|
bitshifter 22 Mar 2010, 04:52
The C language can handle your macro two ways:
#define multiply(x,y) ((x)*(y)) At compile time, if the x and y are resolvable the occurance is replaced with the product of x * y. At run time, if product cannot be resolved, the compiler will insert the appropriate opcodes to get the job done. |
|||
22 Mar 2010, 04:52 |
|
vid 22 Mar 2010, 09:48
Quote: The C language can handle your macro two ways Well, the macro is always handled the same way - string substitution. It's just later that compiler will optimize constant expressions to their result. |
|||
22 Mar 2010, 09:48 |
|
hopcode 26 Mar 2010, 12:49
continuing on the subject that does not persuade me,
sorry if off-topic, but this compile ok Code: if defined @m display "@m defined as constant" end if @m = 40h no antinomy here (btw: in the manual 2.2.6 Multiple passes the typo antinomy instead of antynomy -have we a [st] strikethru on board ?) now, macro are similiar to sym-constant, 2.3.3 Macroinstructions Quote: So if you define macroinstruction and symbolic constant of the same name,... i do it... ... in two steps... Code: macro @m v {db v} if defined @m display "@m defined as constant" ;<---- this never gets displayed end if but this way dosnt compile Code: macro @m v {db v} ;error reserved word used as symbol if defined @m display "@m defined as constant" end if @m = 40h also: if defined and used excludes macroname symbols what the purpouse there in going down to pre-processing stage and raise error ? Or, even if not so useful, defined and used could be enhanced to check for macro-definition. This would be good from external to "shot" an "awareness" of what/if macro were defined in preexisting code. This could correspond to an exist operator Code:
if exist macroname
display "macroname"
end if
Cheears, hopcode _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
26 Mar 2010, 12:49 |
|
revolution 26 Mar 2010, 12:59
hopcode wrote: Or, even if not so useful, defined and used could be enhanced to check for macro-definition. Code: @m = 4 macro @m v {db v} if defined @m ;what does it check for? The macro or the variable ;... Code: SomeNewKeyWord @m { ;do something if @m is defined as a macro (or struc also?) } Last edited by revolution on 26 Mar 2010, 13:54; edited 1 time in total |
|||
26 Mar 2010, 12:59 |
|
hopcode 26 Mar 2010, 13:11
revolution wrote: ...if is only precessed at the assembler stage, Quote: You would have no way to distinguish between a variable and a macro. But you should have the way, already, by design, just because defined and used are for "variables". Or _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
26 Mar 2010, 13:11 |
|
baldr 26 Mar 2010, 19:47
hopcode,
@m is recognized as a macro name only if it is the first token on the line (not counting optional label_name: label definition). Almost the same for struc macro (in this case macro name should be the second token, besides label again). |
|||
26 Mar 2010, 19:47 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.