flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how do I add an alignment value to the struct macro?

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
I need to add an alignment value to the struct macro that would allow me to use the struct in the normal way also. everything that I have tried hasn't worked. I need something like this:
Code:
struct MyStruct, 16
....
ends

;or

struct MyStruct:16
...
ends
;with 16 being the byte alignment value

;and that would let me use struct in the standard way also
struct MyStruct
......
ends
    


this would be useful when dealing with mmx/sse and low level cpu (gpu?) data. Any Ideas?

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 13 Dec 2010, 17:24
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
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 }    
Post 13 Dec 2010, 17:40
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
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?
Post 13 Dec 2010, 17:55
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
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.
Post 13 Dec 2010, 19:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
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?
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.

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.
Post 13 Dec 2010, 21:12
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
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?

it makes me very difficult to do an exaustive "macro" chapter.


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.

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.


All right, I'll give them a read.

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 13 Dec 2010, 22:57
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
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.
I think there is more to this problem that just that. fasm's manual describes all the basic "building blocks" of the language, though it provides only very few examples of how to combine them to create more complex structures out of simple elements. However when you have enough experience, you may notice, that dealing with such problems is actually a more universal ability. If you play with some esoteric languages (well, I also wrote one) you should get a grasp of the idea how is it possible to create amazingly complex things out of very simple blocks. First, you have to know well all of your elements, what each one of them does (some experimenting may be needed). And then... well, it is up to your imagination.
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.
Post 13 Dec 2010, 23:51
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
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
}    
Post 14 Dec 2010, 13:15
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Tomasz Grysztar,

sizeof.struct should be made a multiple of struct's alignment too (to be compliant with C standard Wink). 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)?
Post 14 Dec 2010, 18:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.