The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Jeff on June 30, 2005, 01:20:30 AM

Title: [q]forcing data/code alignment
Post by: Jeff on June 30, 2005, 01:20:30 AM
i (somewhat) understand the pros/cons to having data and code aligned on certain boundaries like having them start at even addresses to increase the speed and such.  so i want to make sure i align data at 4 byte boundaries and code on even (2 byte boundaries).  this brings me to my questions:

is there a (simple) way to make data/code to be aligned at these boundaries within its segment instead of manually placing NOP/ALIGN/EVEN/etc... throughout my code?

also

what is the range of values to be used with the ALIGN directive?  cant put 8 or 16, that overkill?
[edit]
ok got it, use the .486 and above model to go beyond 4
Title: Re: [q]forcing data/code alignment
Post by: hutch-- on June 30, 2005, 07:05:09 AM
Wth data alignment its speed. Trick is to align by at least the data size so that the processor reads the piece of data in one read, not 2. Code alignment varies from processor to processor but may respond well to aligning a label that gets hit a lot of times.

Place the ALIGN keyword before the data you must align in the DATA section. Set it to the size of the data you want to align and with code labels, try a minimum of 4 bytes. The ALIGN directive expects powers of two.



  .data
  align 4
  var dd 1234
  ...........

  align 4
  label: