CPU and Data alignment

Posted by MS on Stack Overflow See other posts from Stack Overflow or by MS
Published on 2010-06-11T18:06:57Z Indexed on 2010/06/11 18:23 UTC
Read the original article Hit count: 330

Filed under:

Dear All,

Pardon me if you feel this has been answered numerous times, but I need answers to the following queries!

  1. Why data has to be aligned (on 4 byte/ 8 byte/ 2 byte boundaries)? Here my doubt is when the CPU has address lines Ax Ax-1 Ax-2 ... A2 A1 A0 then it is quite possible to address the memory locations sequentially. So why there is the need to align the data at specific boundaries?

  2. How to find the alignment requirements when I am compiling my code and generating the executatble?

  3. If for e.g the data alignment is 4 byte boundary, does that mean each consecutive byte is located at modulo 4 offsets? My doubt is if data is 4 byte aligned does that mean that if a byte is at 1004 then the next byte is at 1008 (or at 1005)?

Your thoughts are much welcome.

Thanks in advance! /MS

© Stack Overflow or respective owner

Related posts about alignment