Message board for the users of flat assembler.
> Macroinstructions > Some basic macros for fasm g
While the macros of fasm g should be capable of doing everything that the macros of fasm 1 did, it does not help much when many of the widely-used macros do not have fasm g versions (and this is especially true for Win32/Win64 headers that fasm has, even as incomplete as they have always been). I have converted some of the macros to fasm g syntax when I was adapting it for self-hosting, but these are just some very basic ones, as fasm g sources do not use anything fancy.
One of the reasons why I'm reluctant to simply rewrite/adapt all the macros that came with fasm 1 is that their syntax is often a relic of very early fasm versions that had much simpler macro features, and they remained mostly unchanged to keep the compatibility. When designing similar macros with today's features I would most likely choose a different syntax for many of them, especially ones that build import/export tables and resources in PE.
On the other hand, it would still be nice to have a set of includes providing as much compatibility as possible. All the x86/x64 samples that come in fasm g package, including the Windows examples, are adapted from fasm 1 with no changes - but they do not use any macros that fasm 1 headers for Windows provide. I do not plan to provide more macros in the basic fasm g package (as it focuses on providing basic examples, not complete frameworks), but perhaps another Windows-focused package could be created one day (not necessarily by me?).
Let me show you some of the macros that I created that provide a bit more compatibility but are not included in the basic package.
First, the "struct" macro. The one that I used in fasm g self-hosting headers is a very simple implementation that does not allow to provide initial values in form of parameters to structure. I later made a little modification that adds such feature, but the values have to be labeled instead of providing them in a strict order:
I think this syntax is actually better, while the implementation remains very simple. Making the parameters work in the same way as in the case of fasm's standard macro would require much more complex implementation (probably utilizing "eval"). At the same time, the fasmg variant is much more flexible, since it allows to put any constructions inside the structure, not only ones from the predefined set. You can use "align" or "virtual" inside such structure with not problem. You can even put some CPU instructions there if you needed it for some reason.
macro struct? name macro ends?! end namespace iterate definition, args@struct match name value, definition store value at .name else match name==value, definition store value at .name else match value, definition err 'unnamed values not supported' end match end iterate end struc virtual at 0 name name sizeof.name = $ end virtual purge ends? end macro struc name args@struct& label . sizeof.name namespace . end macro ; usage example struct RECT left dd ? top dd ? right dd ? bottom dd ? ends area RECT left 0,top 0,right 320,bottom 200
The aforementioned flexibility also means that the features like "union" can be implemented as completely independent macros. This simple implementation of "union" I made can be used on its own, but also works correctly when used inside structure defined with the previous macro:
macro union? union?. = $ macro endu?! purge ?,endu? end macro macro ? line& if $-union = 0 line else virtual at union line local size size = $-union end virtual if size > $-union rb size-