flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > how i can return value from macro? something like EXITM. |
Author |
|
dead_body 21 Sep 2005, 08:22
subj. can i do it in fasm now, or it will be in future?
//sorry for bad english |
|||
21 Sep 2005, 08:22 |
|
revolution 21 Sep 2005, 08:56
Code: macro some_macro return_variable,[parameters] { return_variable = something } some_macro the_value,1,2,3,4 mov eax,the_value |
|||
21 Sep 2005, 08:56 |
|
revolution 21 Sep 2005, 09:30
Code: macro strlen soure,op { push source Call GetStringLength ;simple proc op,eax } strlen edi,add ebx strlen edi,mov ecx |
|||
21 Sep 2005, 09:30 |
|
vid 21 Sep 2005, 10:47
tis isn't possible in FASM. anyway "macro" means "macroinstruction", purpose of "macro" is to emulate instruction. what you want is called inline macro, i suggest creating macro for declaring string, which also creates constant with string size, like
Code: struc string [value] {common local ..here ..here: . db value siozeof#. = $ - ..here } my_string string 'aaaaaaaa' mov ecx,sizeof.my_string or you can even overload "db" itself: Code: struc db [value] {common local ..here ..here: . db value siozeof#. = $ - ..here } my_string db 'aaaaaaaa',0 my_data db 10,50,'abc',0 mov ecx,sizeof.my_string mov eax,sizeof.my_data this creates sizeof.<name> for everything defined with "db". For non-constant string, i would suggest this: Code: macro strlen where,what { if !(where eq eax) push eax end if invoke GetStringLength,what if !(where eq eax) mov where,eax pop eax end if } strlen eax,my_string ;puts length of "my_string" to eax Last edited by vid on 21 Sep 2005, 10:54; edited 2 times in total |
|||
21 Sep 2005, 10:47 |
|
dead_body 21 Sep 2005, 10:47
Code: strlen edi,add ebx strlen edi,mov ecx but it looks not very readeble. Maybe in future,when fasm preprocessor will be more powerfull, (exitm <eax>) will be created, am I right Tomasz Grysztar? revolution great thanks to you. You variant is better,yet. |
|||
21 Sep 2005, 10:47 |
|
vid 21 Sep 2005, 10:55
dead_body: seems we replied at the same time, don't miss my reply
IMHO there's no reason to use macro for purpose, 2 extra lines are not problem, and it is more readable than looking for what your macro does etc. |
|||
21 Sep 2005, 10:55 |
|
Tomasz Grysztar 21 Sep 2005, 10:56
No, inlining the macros is something against the fasm's concept. The macro in fasm is just a special kind of "mnemonic", which gets converted into chain of other lines by preprocessor. Just like each assembly language instruction spans one line, the macroinstruction spans one line.
Look at the macros in extended Win32 header (especially the "pushd") to see how this principle affects the solutions. |
|||
21 Sep 2005, 10:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.