As far as I understand, some objects in the "data" section sometimes need alignment in x86 assembly.
An example I've come across is when using movaps
in x86 SSE: I need to load a special constant for later xor
s into an XMM
register.
The XMM
register is 128 bits wide and I need to load a 128-bit long memory location into it, that would also be aligned at 128 bits.
With trial and error, I've deduced that the code I'm looking for is:
section .text
_foo:
movaps xmm0, [xor_const] ; this is the loading part
xor eax, eax
ret
section .data
align 16 ; align to 16 bytes = 128 bits
xor_const: dd 80000000h, 80000000h, 80000000h, 80000000h ; the 128-bit constant
My questions are:
- In which assembly flavors do I use
.align
instead ofalign
? - Do I need to write this keyword/instruction before every data object or is there a way to write it just once?
- What is a relevant documentation I can read about this?
- Is "align" a keyword or an instruction (or maybe something else)?