5 thumb ldm and stm instructions – ARM VERSION 1.2 User Manual

Page 58

Advertising
background image

Writing ARM and Thumb Assembly Language

2-46

Copyright © 2000, 2001 ARM Limited. All 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 can be used to load or store any subset of the 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 instructions 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, Example 2-11 on page 2-44, can be converted into Thumb
instructions (see Example 2-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 after each access. If

LDR

and

STR

were used for this, separate

ADD

instructions would be required to update each base pointer.

Advertising