Achieving correct data alignment in GoAsm
Good alignment can usually be achieved automatically by declaring data in size sequence in the data section. So you would declare all qwords first, then dwords, then words, then bytes and strings. Twords, being 10 bytes, would upset the sequence - you could do them all first then correct the alignment using ALIGN.
Example:

DATA
TWORDINTEGER DT 0.0                ;for floating point operations
TWORDRESULT  DT 0.0
ALIGN 8                            ;re-align data to 8-byte boundary
QWORD_DATA1  DQ 0
QWORD_DATA2  DQ 0
COUNTD1      DD 0
COUNTD2      DD 0
COUNTW1      DW 0
COUNTW2      DW 0
COUNTB      DB 0
Mess1 DB 'Input message',0
Mess2 DB 'Output message',0

Here ALIGN is used to pad the DATA section with zeroes to bring it back into alignment for the qwords.  The same can be done in a CONST section or for unititialised data (using ? as the initialiser).
For Win32, GoAsm automatically aligns structures on a dword boundary, both when they are declared as local data and in the data section.
For Win64 GoAsm automatically aligns structures and structure members to suit the natural boundary of the structure and its members. GoAsm also pads the size of the structure to suit. GoAsm also automatically aligns the stack pointer (RSP) ready for an API call. See the GoAsm help file for more details.

Code alignment in GoAsm
Correct code alignment will differ between processors. There are some speed tests in TestBug which show what difference correct alignment can make when reading from, writing to or comparing the contents of, memory.
When you use ALIGN in a CODE section, GoAsm pads with instruction NOP (opcode 90h), which performs no operation.
Posted on 2007-02-01 03:05:23 by jorgon
haha, recently i had funny alignment problem with FASM.

I had structure, let's say STRUC1

struc STRUC1 x,y,z{
.x dd x+0
.y dd y+0
.z db z+0
}


I wanted to align it

struc STRUC1 x,y,z{
.x dd x+0
.y dd y+0
.z db z+0
align 4  ;<----
}


This worked nicely, structure size was aligned. Later, I "overloaded" it with STRUC2:

struc STRUC2 x,y,z,xx,yy,zz{
. STRUC1 x,y,z
.xx dd xx+0
.yy dd yy+0
.zz db zz+0
align 4
}


This seemed to work too, until once i found that some data of intialized STRUC2 structure were shifted by two bytes against where they should be. It took me nearly hour and half to realize what is happening:

the initialized structure was being declared on unaligned offset. so the resulting declaration (after preprocessing of struct) looked like:

; jano  STRUC2  1,2,3,4,5,6
jano:
.x dd 1
.y dd 2
.z db 3
align 4
.xx dd 4
.yy dd 5
.zz db 6
align 4

first members of structure were declared unaligned, until first align was reached.

So for every structure with aligned members in FASM, also align the structure itself, like this:

struc STRUC1 x,y,z{
align 4
.:
.x dd x+0
.y dd y+0
.z db z+0
align 4
}

but of course, it's always better to use standard STRUCT macros.
Posted on 2007-02-01 04:40:20 by vid
...added Jeremy's contribution to Alignment
Posted on 2007-02-01 09:27:56 by JimmyClif