flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ManOfSteel 28 Dec 2009, 11:58
Include Windows headers in the assembly file only (main.asm) instead of the include files (a.inc and b.inc).
Why make things complicated when they are so simple? |
|||
![]() |
|
Dasn 28 Dec 2009, 12:47
ManOfSteel wrote: Include Windows headers in the assembly file only (main.asm) instead of the include files (a.inc and b.inc). Thanks for your quick reply Man. ![]() Because I often keep my library functions in separate files like 'a.inc' and 'b.inc'. In this example, the 'a.inc' may contain a library function, say 'a_function'; and 'b.inc' may contain a 'b_function', both of which I want to use in my 'main.asm' program, so I include 'a.inc' and 'b.inc' in the 'main.asm'. And both 'a_function' and 'b_function' depend on 'win32ax.inc'. |
|||
![]() |
|
vid 28 Dec 2009, 13:00
This is problematic to do in FASM. Therefor, most people use the system described by ManOfSteel - it surely has its ups and downs.
I think there WAS some macro which was capable of doing conditional include, years ago, but I can't remember anything specific |
|||
![]() |
|
Hapkidoyoka 28 Dec 2009, 14:00
Since eqtype was moved to the pre-parser, I have used something like this.
Code: ;example for 'filename.inc' if inc_filename eqtype 1 define inc_filename "included" ;************************************************** Your code/equates/structures here ;************************************************** end if ;end of include You can then include the file normally, and as many times as you like, Not too good for large projects though - as the file will be loaded a second time but not processed (beyond the wrapping if/end if). |
|||
![]() |
|
revolution 28 Dec 2009, 14:51
Put this in a file and 'include' it in the top of each module. Then use the marco 'includeonce' to include other files multiple times and only one instance is used.
Code: match =files@included,files@included{ macro nest_includeonce\{ macro includeonce path,[instr]\\{\\common file@include equ path match head path tail,files@included\\\{file@include equ\\\} match head path,files@included\\\{file@include equ\\\} match file,file@include\\\{ files@included equ files@included path nest_includeonce include file purge includeonce irp i,instr\\\\{i\\\\} \\\} \\} \}nest_includeonce macro show_included\{match x i,files@included\\{irps j,i\\\{display \\\`j,13,10\\\}\\}\} files@included equ x } |
|||
![]() |
|
Borsuc 28 Dec 2009, 22:52
vid wrote: This is problematic to do in FASM. Code: ; C version #ifndef _SOME_FILE_H #define _SOME_FILE_H ; code #endif ; FASM version match x, _SOME_FILE_INC { define _SOME_FILE_INC ; code } ![]() _________________ Previously known as The_Grey_Beast |
|||
![]() |
|
Azu 31 Dec 2009, 13:53
Borsuc wrote:
![]() |
|||
![]() |
|
Borsuc 31 Dec 2009, 15:38
Azu wrote: I don't get it.. won't the FASM one only define it if it is already defined? Why is the x there?? Match confuses me.. Example: Code: db example ; example is undefined Code: db ; empty It's as if you would do this: Code: define example example ![]() and the 'x' is used to "match anything" -- in other words, it matches any symbol(s) available, which happens all the time unless the symbolic constant is empty... that's what the define does ![]() _________________ Previously known as The_Grey_Beast |
|||
![]() |
|
Azu 31 Dec 2009, 15:43
Yes I know but the C version only defines if it is empty so isn't it the opposite as the FASM version?
![]() |
|||
![]() |
|
Borsuc 31 Dec 2009, 15:50
the C version defines it if it's not defined.
In FASM, the default value of a symbolic constant is its name, not an empty value. So it's the opposite: if you find it is not empty (which it is not by default!), you make it empty to prevent it the second time. When you write: Code: label: xor eax, eax Code: : xor eax, eax for example: Code: define label label: xor eax, eax this is what it looks like by default: Code: define label label label: xor eax, eax ![]() |
|||
![]() |
|
Azu 31 Dec 2009, 15:55
But.. won't that try to define it even if it is already defined? Like I put _SOME_FILE_INC equ 1 above it, it will not be empty, and it will try to define it again.. :/
I think the C version will only try to define it if you haven't already defined it yet. |
|||
![]() |
|
Borsuc 31 Dec 2009, 16:11
Why would you put _SOME_FILE_INC equ 1 above? Of course it would make it fail, it's not supposed to be defined anywhere else.
_________________ Previously known as The_Grey_Beast |
|||
![]() |
|
Azu 31 Dec 2009, 16:18
Well the C version checks to make sure it isn't defined yet. If you don't care to check then a better comparison would be
Code: ; C version #define _SOME_FILE_H ; code ; FASM version define _SOME_FILE_INC ; code |
|||
![]() |
|
Borsuc 31 Dec 2009, 17:47
My method checks if it's empty or not... who said it has to be like C? It works as long as you don't fiddle with that symbolic constant, which applies to C too.
_________________ Previously known as The_Grey_Beast |
|||
![]() |
|
Azu 31 Dec 2009, 17:58
The C one won't define it and put in the code if it is already defined.
The ASM one will. So they aren't different versions of the same thing. They are totally different things. |
|||
![]() |
|
Borsuc 31 Dec 2009, 18:18
What are you talking about?
![]() The C one will check if it is defined -- first time it's not, then defines it. So second time it's included, it will be defined beforehand, and the "if" will be skipped. I mean that's the whole purpose: to include it only once. The asm one does the same thing, except it uses the opposite signals. First time the constant is not empty, so the match matches and then makes it empty, so the second time (and third time etc) it gets skipped because it's empty. The only time it will match is the FIRST time the file gets included -- the exact same behavior as in the C case. I'm not sure what you mean. Both include the file only once no matter how many times you subsequently include it. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.