The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ochazuke on December 27, 2004, 03:34:46 AM

Title: aligning
Post by: ochazuke on December 27, 2004, 03:34:46 AM
can data be aligned in the .data? section?
Title: Re: aligning
Post by: hutch-- on December 27, 2004, 03:43:11 AM
It surely can. As long as you set the processor model at the start of the file to .486 or higher, you can align data by up to 16 bytes. On DWORD size data you normally require alignment by 4 bytes.

align 2    ; old WORD alignment
align 4    ; normal DWORD alignment
align 8
align 16

With SSE/2 and other specialised circumstances where you need alignment by 32 bytes you allocate memory and write the data to an aligned location in the memory buffer.

You normally place the "align" directive before the item that needs to be aligned in the .DATA section like as follows.

  .data?
    align 4
    myitem dd ?
Title: Re: aligning
Post by: ochazuke on December 27, 2004, 03:54:26 AM
Thanks for the reply!  I wonder though, how is data in the .data? section allocated?  In my project I have to allocate about 600kb, and when I had it in the .data section, not only did the assembling take forever but my application size increased by about 600 kb  :eek.
Title: Re: aligning
Post by: donkey on December 27, 2004, 04:41:48 AM
The .data? section is uninitialized data, it does not add to the size of your executable. The .data section however does add to the size of the executable. Generally you can rely on uninitialized data being filled with 0 so if you are just creating empty data put it in the .data? section as there is no need to initialize it to zero.