SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What are the post-indexed addressing modes in Arm Cortex M?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What are the post-indexed addressing modes in Arm Cortex M?

Graham Kruk
Last updated: October 5, 2023 9:52 am
Graham Kruk 6 Min Read
Share
SHARE

Post-indexed addressing modes in Arm Cortex M refer to addressing modes where the address is calculated first before being used, and then the address register is updated after. This allows efficient accessing of data structures like arrays or buffers where you want to increment the address after each access. The key benefit is that the updated address is available for the next instruction without needing an extra ADD instruction.

Contents
Background on Arm Addressing ModesPost-Indexed Addressing Modes in Arm Cortex MPost-Indexed Addressing with OffsetPost-Indexed Addressing with Immediate OffsetPost-Indexed Addressing with Register and ShiftPost-Indexed Addressing with Scaled Register OffsetUse Cases for Post-Indexed AddressingAccessing Array DataStepping Through Buffers or Linked ListsStructured Data AccessMemory Block CopyComparison to Pre-Indexed AddressingDefining Post-Indexed Addressing in AssemblyPost-Indexed Addressing and Multicore CompatibilitySummary

Background on Arm Addressing Modes

The Arm architecture supports a flexible set of addressing modes for load and store instructions to access memory. These work by using a base register, an offset register, a shift amount, and an offset constant to calculate the memory address. The three main types of addressing are:

  • Offset – The address is the sum of a base register and an optionally shifted offset register.
  • Pre-indexed – The base register is updated with the offset before using the address.
  • Post-indexed – The address is calculated first before the base register is updated with the offset.

Post-indexed addressing is useful for sequentially accessing data structures because you get the updated base register pointing to the next element without needing a separate ADD instruction. The Arm Cortex-M processors like Cortex-M3, Cortex-M4, and Cortex-M7 support several post-indexed addressing modes for loads and stores.

Post-Indexed Addressing Modes in Arm Cortex M

Here are the main post-indexed addressing modes supported on Cortex-M processors:

Post-Indexed Addressing with Offset

This uses the base register value as the address for the load/store. After completing the memory access, the offset register value is added to the base register. For example: LDR R0, [R1], R2

Loads from the address in R1, then does R1 = R1 + R2. This allows efficiently stepping through arrays or buffers.

Post-Indexed Addressing with Immediate Offset

Same as above but with an immediate constant offset instead of a register. For example: LDR R0, [R1], #8

Loads from R1 then does R1 = R1 + 8. Useful for accessing fields of structured data.

Post-Indexed Addressing with Register and Shift

Supports shifted register offsets for the post-increment step. For example: LDR R0, [R1], R2, LSL #3

Loads from R1, then does R1 = R1 + (R2 << 3) to increment the base address.

Post-Indexed Addressing with Scaled Register Offset

A specialized mode to support efficient array access. The index register is automatically scaled by the data size. For example: LDR R0, [R1], R2, LSL #2

Loads from R1, then does R1 = R1 + (R2 * 4) to move to the next array element.

Use Cases for Post-Indexed Addressing

Here are some typical use cases where post-indexed addressing is useful on Cortex-M:

Accessing Array Data

Post-indexed array addressing like LDR R0, [R1], R2, LSL #2 is very efficient for array access in a loop since it handles the index increment automatically.

Stepping Through Buffers or Linked Lists

Post-increment with the offset register is ideal for sequentially going through a buffer or linked list data structure.

Structured Data Access

The immediate offset post-indexed mode allows accessing different fields of a struct or object and automatically advancing to the next field.

Memory Block Copy

Post-increment load and store instructions can be used together to implement an efficient memory block copy routine.

Comparison to Pre-Indexed Addressing

Pre-indexed addressing updates the base register first before doing the memory access. This causes a subtle change in behavior for things like array access. With pre-indexing, the updated base is used for the current access which means it points to the next element. With post-indexing, the original base is used meaning it points to the current element.

So post-indexed addressing is better suited for sequential access patterns where you want to access the current element before stepping to the next.

Defining Post-Indexed Addressing in Assembly

Here are some examples of using post-indexed addressing modes in Arm assembly on Cortex-M: LDR R0, [R1], R2 ; Post-indexed offset register LDR R0, [R1], #8 ; Post-indexed immediate offset LDR R0, [R1], R2, LSL #3 ; Post-indexed shifted register offset LDR R0, [R1], R2, LSL #2 ; Post-indexed scaled array indexing

The assembly syntax is straightforward – the increment step comes after the base register in square brackets. This clearly indicates the post-increment behavior.

Post-Indexed Addressing and Multicore Compatibility

Post-indexed addressing modes are supported across all profiles of the Arm architecture including both Cortex-M and Cortex-A series processors. This makes post-indexing suitable for software targeting multiple Arm core types. The specific opcodes differ but the fundamental behavior is consistent.

Summary

In summary, post-indexed addressing is useful for:

  • Efficient array access without extra ADD instructions
  • Stepping through data structures like buffers and lists
  • Structured data field access
  • Memory block copy operations

The post-increment happens after the memory access which sets up the base register for the next sequential access. Post-indexing is straightforward to use in assembly code and supported on all Arm profiles so is widely usable across Arm-based software.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What are the pre-indexed addressing modes in Arm Cortex M?
Next Article Branch Instructions in ARM Cortex-M
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Using the Cortex-M0 DesignStart Soft Core with MPS2+

The Cortex-M0 DesignStart soft core provides a low-cost entry point…

6 Min Read

Printf Retargetting for Nano-Specs Cortex M0

The Cortex-M0 is an ultra low power 32-bit ARM Cortex-M…

6 Min Read

Does Normal memory, and Device memory really affect the system behavior? Cortex M0/M0+

The simple answer is yes, the type of memory used…

5 Min Read

Modifying Stack Pointer (SP) and Program Counter (PC) in Cortex-M1

The stack pointer (SP) and program counter (PC) are important…

6 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account