flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > how do I add an alignment value to the struct macro? |
Author |
|
Tomasz Grysztar 13 Dec 2010, 17:40
Here is a simple wrapper that should do it even regardless of what "struct" implementation you use:
Code: ; include if AFTER the struct macros macro struct name,alignment { define alignment@struct name:alignment struct name } macro union { define alignment@struct union } macro ends { ends match name:alignment,alignment@struct \{ struc name [params] \\{ \\common align alignment . name params \\} macro name [params] \\{ \\common align alignment name params \\} \} restore alignment@struct } |
|||
13 Dec 2010, 17:40 |
|
madmatt 13 Dec 2010, 17:55
After a few quick trials, it seems to work good. Thanks! Do you plan on updating the fasm manual with more advanced examples on how to use macro{} command feature's? I would have never have figured out all the 'code' you just posted by just reading the manual. Perhaps a walkthru of the struct and/or proc32 macros?
|
|||
13 Dec 2010, 17:55 |
|
edfed 13 Dec 2010, 19:32
fasm macro seems to be very powerfull, i am pretty sure that you (TG)didn't explore all its possibilities, and find them time to time... isn't it?
it makes me very difficult to do an exaustive "macro" chapter. |
|||
13 Dec 2010, 19:32 |
|
Tomasz Grysztar 13 Dec 2010, 21:12
madmatt wrote: After a few quick trials, it seems to work good. Thanks! Do you plan on updating the fasm manual with more advanced examples on how to use macro{} command feature's? I would have never have figured out all the 'code' you just posted by just reading the manual. Perhaps a walkthru of the struct and/or proc32 macros? There is also this tutorial on MATCH directive that I once wrote and I actually plan to make it part of "Understanding fasm" in the future. |
|||
13 Dec 2010, 21:12 |
|
madmatt 13 Dec 2010, 22:57
edfed wrote: fasm macro seems to be very powerfull, i am pretty sure that you (TG)didn't explore all its possibilities, and find them time to time... isn't it? I have written some of my own macros, but the fasm documentation only describes basic macro operations, not the more advanced stuff. If it had the more advanced stuff, I possibly could have written the additions myself. Quote: I started writing such text long time ago, it is called Understanding fasm, however I wrote just the beginning and I constantly forget to get back to this project. All right, I'll give them a read. _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
13 Dec 2010, 22:57 |
|
Tomasz Grysztar 13 Dec 2010, 23:51
madmatt wrote: I have written some of my own macros, but the fasm documentation only describes basic macro operations, not the more advanced stuff. If it had the more advanced stuff, I possibly could have written the additions myself. In fact assembly language is also an example of such a thing - you can implement very intricate algorithms using just a few elementary instructions. But - in my opinion - the more examples of such emergence you know, the better. It can be real fun to play with various languages, I even find it very refreshing to study some old and now rarely used languages, like LISP or SNOBOL, to see how you can deal with having some building blocks completely different from the ones you are used to. |
|||
13 Dec 2010, 23:51 |
|
madmatt 14 Dec 2010, 13:15
Yeh, I should set aside a few days just to experiment with macro's and learn all the details of what they can do. I've written a few simple macro's (see below) that solved some immediate problems that I had, but never got farther in making more complex macros. With the extra information that you've provided, I should do that soon.
Code: macro fldq dfloat { local ..mynumber, ..here fld [..mynumber] jmp ..here align 8 ..mynumber dq dfloat ..here: } macro fldd dfloat { local ..mynumber, ..here fld [..mynumber] jmp ..here align 4 ..mynumber dd dfloat ..here: } macro fildd integer { local ..mynumber, ..here jmp ..here align 4 ..mynumber dd integer ..here: fild [..mynumber] } macro STRUCTARRAY name, structname, [args] { common if used name name: end if forward structname args sizeof.#name = $ - name countof.#name = ($ - name)/ sizeof.#structname } |
|||
14 Dec 2010, 13:15 |
|
baldr 14 Dec 2010, 18:43
Tomasz Grysztar,
sizeof.struct should be made a multiple of struct's alignment too (to be compliant with C standard ). Probably alignof.struct could be useful for dynamically allocated structures (or arrays of them). SNOBOL and LISP (along with FORTH) are esoteric/rare enough, what do you think of Simula (and Smalltalk thereof)? |
|||
14 Dec 2010, 18:43 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.