Writing ARM and Thumb Assembly Language
2-46 Copyright © 2000, 2001 ARM Limited. A ll rights reserved. ARM DUI 0068B
2.8.5 Thumb LDM and STM instructions
The Thumb instruction set contains two pairs of multiple-register transfer instructions:
LDM
and
STM
for block memory transfers
PUSH
and
POP
for stack operations.
LDM and STM
These instructions ca n be used to load or s tore any subset of th e low registers from or
to memory. The base register is always updated at the end of the multiple register
transfer instruction. You must specify the
!
character. The only valid suffix for these
instructions is
IA
.
Examples of these instruct ions are:
LDMIA r1!, {r0,r2-r7}
STMIA r4!, {r0-r3}
PUSH and POP
These instructions can be used to push any subset of the low registers and (optionally)
the link register onto the stack, and to pop any subset of the low registers and
(optionally) the pc off the stack. The base address of the stack is held in r13. Examples
of these instructions are:
PUSH {r0-r3}
POP {r0-r3}
PUSH {r4-r7,lr}
POP {r4-r7,pc}
The optional addition of the lr or pc to the register list provides support for subroutine
entry and exit.
The stack is always full descending.
Thumb-state block copy example
The block copy example, Example2-11 on page 2-44, can be converted into Thumb
instructions (see Example2-13 on page 2-47).
Because the Thumb
LDM
and
STM
instructions can access only the low registers, the
number of words copied per iteration is reduced from eight to four. In addition, the
LDM
and
STM
instructions can be used to carry out the single word at a time copy, because they
update the base pointer a fter each access. I f
LDR
and
STR
were used for this, separate
ADD
instructions would be required to update each base pointer.