Search code examples
assemblyarmgnu-assembler

What does .align in ARM architecture


I am new to assembly level coding so I am bit confused what .align does. I have looked up what it does in many places.https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok05.html in this link a description on .align is given in red box on the right hand side of the page. Another place i refereed was http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489c/Babecdje.html. What does it mean for a address to be 4 bytes aligned or 8 bytes aligned ?

If I use the following instructions in my code

.align 4
pattern:

Then does mean the address assigned to pattern will be of the form 4*n or 16*n ( 2^4 = 16).


Solution

  • An address is said to be "n-bytes aligned" if it's evenly divisible by n.

    This can also be expressed as "an address is 2m-bytes aligned if its rightmost m bits are all zero".

    Alignment is very common a requirement, i.e. the hardware requires as part of its programming model that certain alignment requirements are always respected. Failure to do so might lead to a hard fault, i.e. the processor stops.