4.2.14. SWP and SWPB

Swap data between registers and memory.

Syntax

SWP{B}{cond} Rt, Rt2, [Rn]

where:

cond

is an optional condition code (see Conditional execution).

B

is an optional suffix. If B is present, a byte is swapped. Otherwise, a 32-bit word is swapped.

Rt

is the destination register.

Rt2

is the source register. Rt2 can be the same register as Rt.

Rn

contains the address in memory. Rn must be a different register from both Rt and Rt2.

Usage

You can use SWP and SWPB to implement semaphores:

  • Data from memory is loaded into Rt.

  • The contents of Rt2 is saved to memory.

  • If Rt2 is the same register as Rt, the contents of the register is swapped with the contents of the memory location.

Note

The use of SWP and SWPB is deprecated in ARMv6 and above. See LDREX and STREX for instructions to implement more sophisticated semaphores in ARMv6 and above.

Architectures

These ARM instructions are available in all versions of the ARM architecture.

There are no Thumb SWP or SWPB instructions.

Copyright © 2002-2010 ARM. All rights reserved.ARM DUI 0204J
Non-ConfidentialID101213