flat assembler
Message board for the users of flat assembler.

 Index > Main > How to align SSE variables
Author
SDragon

Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon 13 Sep 2005, 05:31
I have the following code:
Code:
```format MS COFF ; it's an .obj file to be linked with MSVC++ program
include '%fasminc%\win32a.inc'
; align 16
cx1 dd 4 dup ?
cy1 dd 4 dup ?
; some other declarations

proc PaintSSE c
; some other code
MOVAPS dqword[cx1], xmm0 ; NEED 16-byte align here!
MOVAPS dqword[cy1], xmm1
; some other code
endp
public PaintSSE as '_PaintSSE'    ```

How to align cx1 and cy1 on 16-byte boundary? I've tried align 16, but it reports "section is not aligned enough". This macro from manual:
Code:
`macro align value { rb (value-1)-(\$+value-1) mod value }    `

doesn't help too (it says "invalid expression").
How do I align 128-bit variables?
13 Sep 2005, 05:31
Reverend

Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 13 Sep 2005, 15:17
Although my macro posted below works alright, I had to use virtual, and don't have an idea why doesn't it work the way you had it.
Code:
```macro dalign value {
virtual
dd \$
end virtual
rb value-(__ADDR mod value) }    ```
13 Sep 2005, 15:17
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8096
Location: Kraków, Poland
Tomasz Grysztar 13 Sep 2005, 15:49
Quote:
I've tried align 16, but it reports "section is not aligned enough".

This means you have to align the section first - when section is not aligned on 16 bytes boundary, aligning the data relatively to the beginning of this section is useless. For the same reason you cannot use \$ symbol this way, since assembler doesn't know at what address this section will be put by the linker/loader. To align the section, you declare it like:
Code:
`section '.data' data readable writeable align 16    `

This tells the linker that this section should be put at aligned address; and thus assembler can do "align 16" and smaller alignments inside such section without problems (and in the beginning of section you even don't have to do additional alignment).
13 Sep 2005, 15:49
SDragon

Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon 14 Sep 2005, 00:49
Thank you very much, Tomasz. It works!
14 Sep 2005, 00:49
Reverend

Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 16 Sep 2005, 20:56
Tomasz: Why is it so? Sections in PE are aligned always to at least 512, so I guess all alignments in sections below that value should be possible. I agree with your point of view (as I understand it), but only for alignment values greater than the default 512.
16 Sep 2005, 20:56
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Feb 2006, 15:45
15 Feb 2006, 15:45
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8096
Location: Kraków, Poland
Tomasz Grysztar 15 Feb 2006, 15:58
The sections in COFF are not the same thing as sections in PE - the linker may compose the final PE section out of many COFF sections of the same name, and when it concatenates them, it uses the alignment specified for each of them.
15 Feb 2006, 15:58
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum