Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top