وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

Aligning Data


Aligning Data   ...



When an Instruction accesses a Memory location, for reading or for writing, if the targeted data is not aligned, in Memory, on its own Boundary, the Processor performs two Memory accesses instead of one. To prevent  this penalty, you have to take care of always aligning your data on their own Boundary.


Aligning a Byte Data on its own boundary: Nothing to do.


Aligning a Word Data on  its own boundary: The binary form of the Address must be 00_xxxx...xx00


Aligning a dWord Data on its own boundary:  The binary form of the Address must be 00_xxxx...0000


Aligning a qWord Data on its own boundary:  The binary form of the Address must be 00_xxxx...0000_0000


You may use an Align_On Macro, for doing this:


[Align_on | add #2 #1-1 | and #2 0-#1]


> Align_On 8, edi    ; 8 or any Power of 2.



When declaring Data with RosAsm, each time you open a new Square Bracket, RosAsm does the alignment for you, by default. (You may get rid of it, as explained in the RosAsm Manual). RosAsm's default Alignment is on four Byte Boundaries. See how to force this alignment to another boundary in the RosAsm Manual in Data_Management.



There is not only a real speed consideration with this: In the new Windows versions, the Api Functions are more and more sensitive to the Alignment of Data, particularly for Structures. Some Functions would simply fail, if the provided Structures are not aligned on four Byte boundaries.


~~~~~~~