AArch64/ARM64 Tutorial

Chapter 11: Pre and Post Index of Loads/Stores

Loads and Stores can have additional operations done to them to update the Source Register's Address immediately *after* the instruction has executed. This can come in handy for something such as a Loop which you will learn about in the next Chapter.

Example Pre-Index Store:
str x0, [x1, #0x4]! //Take note of the exclamation point at the end of the instruction highlighted in yellow. This indicates the store is a pre-index store.

What occurs on the above instruction is...

  1. x1 + 0x4 = Effective Address
  2. x0 (entire double-word) stored at Effective Address
  3. x1 is then incremented by 0x4, it now has a new value if the instruction gets executed again

As you can see, to simply add a pre-index feature to a load/store, just append the instruction with a "!". 

Confused? Let's go over some pics.

Pretend x0 = 5
Pretend x1 = 0x40008002B0

Let's say we execute "str x0, [x1, #0x4]!". Here's a pic of right before the instruction is executed which also includes the view of 16 bytes of Memory starting at 0x40008002B0.

You can see that x5 (outlined in green) is 5, and x1 (outlined in red) is 0x40008002B0. The double-word outlined in magenta is where x0 will be stored to (x1 + 4) when the instruction (outlined in blue) does execute. We can see in the pic, the magenta outlined contents in memory are all zero. Once the instruction executes, those values will be replaced.

Okay let's say we execute the instruction now. Here's the pic.

We can see that x0 was stored to 0x40008002B4 (Effective Address which was x1 + 4). We also see that x1 was updated to have the new value 0x40008002B4 after the store was preformed. The green arrow shows how the contents of x0 (outlined in green) were stored to 0x40008002B4 (outlined in magenta). Because of Little Endian, the value was changed to 0x0500000000000000 when the store actually occurred to Memory.


Example Post-Index Store:
str x0, [x1], #0x4 //Take note of how the Source Register alone is enclosed in brackets with the Immediate Value being placed after a second comma

What occurs:

  1. x1 = Effective Address
  2. x0 (entire double-word) stored at Effective Address
  3. x1 is then incremented by 0x4, it now has a new value if the instruction gets executed again

Still confused? Let's go over some pics.

Pretend x0 = 5
Pretend x1 = 0x40008002B0

Here's a pic of right before the instruction (str x0, [x1], #0x4) is executed which also includes the view of 16 bytes of Memory starting at 0x40008002B0.

You can see that x5 (outlined in green) is 5 and x1 (outlined in red) is 0x40008002B0. The double-word outlined in magenta is where x0 will be stored to when the instruction (outlined in blue) does execute. We can see in the pic, the magenta outlined contents in memory are all zero. Once the instruction executes, those values will be replaced.

Okay let's say we execute the instruction now. Here's the pic.

We can see that x1 has been incremented by 4 (to 0x40008002B4). We also see that x0's contents were stored at 0x40008002B0 *BEFORE* x1 was incremented by 0x4. The green arrow shows how the contents of x0 (outlined in green) were stored to 0x40008002B0 (outlined in magenta). Because of Little Endian, the value was changed to 0x0500000000000000 when the store actually occurred to Memory.


Now let's cover pre and post index loads...

Example Pre-Index Load:
ldr w5, [x16, #0x3C]!

What occurs:

  1. x16 + 0x3C = Effective Address
  2. Word value located at Effective Address is loaded into w5.
  3. x16 is then incremented by 0x3C, it now has a new value if the instruction gets executed again

Example Post-Index Load:
ldr w5, [x16], #0x3C

What occurs:

  1. x16 = Effective Address
  2. Word value located at Effective Address is loaded into w5.
  3. x16 is then incremented by 0x3C, it now has a new value if the instruction gets executed again

Next Chapter

Tutorial Index