flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > some data defining macros

Author
Thread Post new topic Reply to topic
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 29 Oct 2007, 11:43
I use the following macros for data definitions.

Code:
ela= 1;element align

struc    db      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   db      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 1;element size
}

struc    dw      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   dw      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 2
}
struc     du      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   du      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 2
}

struc dd      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   dd      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 4
}

struc df      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   df      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 6
}
dp        equ df

struc     dq      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   dq      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 8
}

struc dt      [arg] {
common
local do_align, cnt
@@:
  cnt= 0
  define        do_align        1
forward
  if arg eqtype align 0
    arg
    define        do_align        0
  else
    if do_align eq 1
 align   ela
    end if
   dt      arg
    define       do_align        1
  end if
  cnt= cnt + 1
common
  .size= $ - @b
  .cnt= cnt
  .els= 10
}

struc        dstr    [arg] {
common
local do_align, cnt
       dd      .size
@@:
  cnt= 0
  if ~arg eq
    define      do_align        1
forward
    if arg eqtype align 0
      arg
      define  do_align        0
    else
      if do_align eq 1
     align   ela
      end if
 db      arg
      define     do_align        1
    end if
    cnt= cnt + 1
common
  end if
   db      \n
  .size= $ - @b
  .cnt= cnt
  .els= 1
}
    

They especially allow you to use custom aligns within 1 list of arguments.
I don't know whether this is useful, but I though it may be handy sometime:
Code:
dat1 dd 1,2,align 16,3,4
    

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 29 Oct 2007, 11:43
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3892
Location: vpcmipstrm
bitRAKE 21 Mar 2008, 23:29
I had a similar problem and created an align macro which allows an offset also to be specified:
Code:
macro ALIGN val,off { rb (val+off-($ mod val))mod val }    
This works on code and data. For example, you example would be:
Code:
ALIGN 16,8
dat1 dd 1,2,3,4    
...or if there is a desire to align an inner loop to a cacheline boundary:
Code:
ALIGN 64,(64-inner+mainProc)

mainProc:

  ; some code

inner: ; aligned inner loop    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 21 Mar 2008, 23:29
View user's profile Send private message Visit poster's website 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.