0
0
Cnc-programmingConceptBeginner · 3 min read

Pre Indexed Addressing in ARM: Explanation and Example

In ARM architecture, pre-indexed addressing is a way to access memory where the base register is updated by adding or subtracting an offset before the memory access happens. This means the address used for the load or store instruction is the base register plus the offset, and the base register itself is updated with this new address.
⚙️

How It Works

Pre-indexed addressing in ARM works by first modifying the base register with an offset value, then using this updated address to access memory. Imagine you have a bookmark pointing to a page in a book (the base register). Before reading, you move the bookmark forward or backward by some pages (the offset). Then you read the content at the new page where the bookmark now points.

This method is useful because it combines the address calculation and memory access into one instruction, saving steps. The base register is automatically updated, so you don't need a separate instruction to change it.

💻

Example

This example shows how pre-indexed addressing loads a value from memory after adjusting the base register by an offset.

arm
LDR R1, [R0, #4]!  ; Load value from address (R0 + 4) into R1, then update R0 to R0 + 4
🎯

When to Use

Use pre-indexed addressing when you want to access a memory location relative to a base pointer and update that pointer in one step. This is common in loops processing arrays or buffers, where you move through memory sequentially.

For example, when reading elements from an array, pre-indexed addressing lets you load the current element and move the pointer to the next element automatically, making your code shorter and faster.

Key Points

  • Pre-indexed addressing updates the base register before memory access.
  • The offset can be positive or negative to move forward or backward.
  • It combines address calculation and memory access in one instruction.
  • Useful for efficient pointer updates in loops and data processing.

Key Takeaways

Pre-indexed addressing updates the base register before accessing memory.
It simplifies code by combining address calculation and memory access.
Ideal for sequential data processing like array traversal.
The offset can add or subtract from the base address.
Using it can improve performance and reduce instruction count.