Post Indexed Addressing in ARM: Explanation and Example
post indexed addressing is a way to access memory where the address used for the operation is the original register value, and then the register is updated by adding or subtracting an offset after the access. This means the instruction uses the current address first, then changes the register for the next operation.How It Works
Post indexed addressing in ARM works like this: you have a register holding a memory address. The CPU uses this address to read or write data first. After this memory operation, the CPU updates the register by adding or subtracting a specified offset.
Think of it like a bookmark in a book. You read the page where the bookmark is placed, then move the bookmark forward or backward to the next page for future reading. The key point is that the memory access happens before the register changes.
This is different from pre indexed addressing, where the register is updated first, then used for the memory access. Post indexed addressing is useful when you want to use the current address and then prepare the register for the next step.
Example
This example shows a load instruction using post indexed addressing. It loads a value from the address in r0, then adds 4 to r0 after the load.
LDR r1, [r0], #4When to Use
Post indexed addressing is useful when processing data sequentially in memory, such as iterating through arrays or buffers. It lets you load or store data at the current address and automatically update the pointer for the next element.
For example, in a loop reading sensor data or copying memory blocks, post indexed addressing reduces extra instructions needed to update the address register separately. This makes the code shorter and faster.
Key Points
- Post indexed addressing uses the original register value for memory access first.
- The register is updated by the offset only after the access.
- It simplifies code when processing data sequentially in memory.
- Commonly used in loops for arrays or buffers.