1

Reading through a paper for the ARM Cortex-M3 CPU I found this line confusing:

The lowest 2 bits of the stack pointers are always 0, which means they are always word aligned

I have seen similar statements elsewhere. What is the logic behind some zero bits => some alignment?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

If the 2 LS bits are always zero then addresses can only be multiples of 4, i.e. addresses can only be:

Hex      Binary
xxxxxxx0 bbbbbbbbbbbbbbbbbbbbbbbbbbbb0000
xxxxxxx4 bbbbbbbbbbbbbbbbbbbbbbbbbbbb0100
xxxxxxx8 bbbbbbbbbbbbbbbbbbbbbbbbbbbb1000
xxxxxxxc bbbbbbbbbbbbbbbbbbbbbbbbbbbb1100

(If it helps, think of the equivalent in decimal - any number that ends in 00 is a multiple of 10^2 = 100).

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Oh of course. Somehow I thought the pointers themselves were aligned when stored - not that they pointed to aligned data.. –  Dec 10 '10 at 22:14