• Home
  • QUESTIONS & ANSWERS
  • Integrated Circuits (ICs)
  • What are the LDM and STM command modes?

    * Question

    What are the LDM and STM command modes?

    * Answer

    In ARM architecture, LDM (Load Multiple) and STM (Store Multiple) are block data transfer instructions that move multiple register values between memory and the CPU in a single instruction. Both have several command modes that define how the memory address pointer is updated during the transfer.

    1. Addressing Modes for LDM/STM

    The addressing mode is encoded in the instruction suffix and determines the direction of memory access and when the base register is updated.

    Mode

    Meaning

    Memory Access Direction

    Example

    IA (Increment After)

    Start at base address, transfer data, then increment address

    Ascending addresses, start at base

    LDMIA R0!, {R1-R4}

    IB (Increment Before)

    Increment address first, then transfer

    Ascending addresses, start one word higher

    STMIB R0!, {R1-R4}

    DA (Decrement After)

    Start at base address, transfer data, then decrement address

    Descending addresses, start at base

    STMDA R0!, {R1-R4}

    DB (Decrement Before)

    Decrement address first, then transfer

    Descending addresses, start one word lower

    LDMDB R0!, {R1-R4}

    2. LDM (Load Multiple) Command Modes

    LDMIA — Load registers from memory starting at base address, then increment after each transfer.

    LDMIB — Increment address first, then load registers.

    LDMDA — Load from base address, then decrement after each transfer.

    LDMDB — Decrement address first, then load registers.

    Usage example:

    asm

    LDMIA R0!, {R1, R2, R3, R4}  ; Load R1-R4 from memory, update R0

    3. STM (Store Multiple) Command Modes

    STMIA — Store registers to memory starting at base address, increment after each transfer.

    STMIB — Increment address first, then store registers.

    STMDA — Store at base address, decrement after.

    STMDB — Decrement address first, then store registers.

    Usage example:

    asm

    STMFD SP!, {R0-R3, LR}  ; Store multiple registers, full descending stack

    (Here FD is an alias for Full Descending, which maps to STMDB.)

    4. Stack Operation Aliases

    In ARM assembly, certain suffix aliases are used for stack operations:

    STMFD / LDMFD — Full Descending stack (STMDB / LDMIA)

    STMED / LDMED — Empty Descending stack (STMDA / LDMIB)

    STMFA / LDMFA — Full Ascending stack (STMIB / LDMDA)

    STMEA / LDMEA — Empty Ascending stack (STMIA / LDMDB)

    These aliases are just mnemonics that map to the IA/IB/DA/DB modes.

    Summary

    LDM = Load multiple registers from memory.

    STM = Store multiple registers to memory.

    Four modes (IA, IB, DA, DB) control increment/decrement and before/after addressing.

    Stack operation aliases (FD, ED, FA, EA) make it easier to write push/pop style code.

    COMMENTS

    WORDPRESS: 0
    DISQUS: 0