flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [solved] How to eliminate cinvoke |
Author |
|
JohnFound 04 Aug 2012, 09:22
Don't use "fix" it has special function and should not be used for such things.
Use macro instead. IMHO, eliminating "cinvoke" is not a good idea. It will make the code less readable. Remember, Assembler is not HLL. Assembler has it's own syntax and writing style. If you like HLL style, better use C++. |
|||
04 Aug 2012, 09:22 |
|
Picnic 04 Aug 2012, 11:14
You're probably right, nevertheless i like to consider fasm as my programming language environment, not strictly as assembler and i enjoy having HLL style in asm.
Actually for me, code is less boring and more readable this way. Anyway, can you please explain why using fix is wrong, you have some other way to eliminate cinvoke? Last edited by Picnic on 04 Aug 2012, 11:34; edited 1 time in total |
|||
04 Aug 2012, 11:14 |
|
revolution 04 Aug 2012, 11:32
Perhaps the question to answer here is why you want to eliminate cinvoke? If you can answer that then you might get more help from others once they realise the reason for it.
Last edited by revolution on 04 Aug 2012, 11:33; edited 1 time in total |
|||
04 Aug 2012, 11:32 |
|
JohnFound 04 Aug 2012, 11:33
Code: macro strrchr, [arg] { common cinvoke strrchr, arg } |
|||
04 Aug 2012, 11:33 |
|
Picnic 04 Aug 2012, 11:41
JohnFound wrote:
Thanks for the snippet JohnFound. revolution wrote: Perhaps the question to answer here is why you want to eliminate cinvoke? If you can answer that then you might get more help from others once they realise the reason for it. I am writing a program in which there is no other library in use other than msvcrt. It's some kind of parser to handle text files exported in a specific form, from a commercial program we use at work. The code looks much nicer without cinvoke. |
|||
04 Aug 2012, 11:41 |
|
IceStudent 06 Sep 2012, 11:29
|
|||
06 Sep 2012, 11:29 |
|
l_inc 07 Sep 2012, 20:02
Picnic
First of all what you're trying to do is impossible. You said, you were trying to "fix" everything at the preprocessing stage, but at the same time you were only using the assembly stage directives. Secondly, it's a mistake to take the name between the quotes, because what is actually used in the source is a label. And the label is the symbol before the quoted string. Thirdly, I completely agree with JohnFound, that the fix directive is for the special purposes only. Fourthly, your solution with fix could only work when defining the import table before "fixing". Otherwise such "fixing" would also replace label declarations with an uncompilable crap making the "fixed" functions useless. Fifthly, what you actually need to do is the following: Code: macro api [args] {} macro import lib,[label,string] { macro label [args] \{ \common cinvoke label,args \} } include 'msvcrt.inc' purge api,import macro import [args] { common macro purgelabels lib,[label,string] \{ \common purge label \} purgelabels args purge purgelabels import args } After that you can call the msvcrt functions as follows: Code: strrchr mystr,',' |
|||
07 Sep 2012, 20:02 |
|
Picnic 08 Sep 2012, 11:11
@IceStudent thanks for your reply.
@l_inc i just tried the code and works fine. Correct me if i'm wrong, first you redefine api and import macros, and after you include the functions using the new import macro, you restore them, so simple... Now, can you please explain what the second import macro does. I noticed that if i ommit it, my program still compiles without the need for cinvoke. Thank you. |
|||
08 Sep 2012, 11:11 |
|
l_inc 08 Sep 2012, 12:16
Picnic
Quote: first you redefine api and import macros, and after you include the functions using the new import macro, you restore them, so simple... That's correct. I'm not sure, whether your msvcrt.inc contains an api-macro call. If it doesn't, than you don't need to redefine it. Quote: I noticed that if i ommit it, my program still compiles without the need for cinvoke. That's probably because you define the import table before the provided macros. If you define the import table afterwards, the function labels will conflict with the macros as described in "fourthly", and the compilation will fail. To prevent the conflict, the second import macro again makes use of the list of labels and undefines the macros, defined by the previous include 'msvcrt.inc'. |
|||
08 Sep 2012, 12:16 |
|
uart777 10 Sep 2012, 14:45
[ Post removed by author. ]
Last edited by uart777 on 17 Nov 2013, 00:31; edited 1 time in total |
|||
10 Sep 2012, 14:45 |
|
AsmGuru62 10 Sep 2012, 16:23
cinvoke is more readable than a group of PUSH-es and a CALL.
If a macro creates more readable code - it is a good macro. If a macro hides a lot of code - it is not a good macro. These above ^^^ are just my personal opinions. I welcome everyone to contribute to FASM with whatever they can. |
|||
10 Sep 2012, 16:23 |
|
uart777 11 Sep 2012, 12:56
[ Post removed by author. ]
|
|||
11 Sep 2012, 12:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.