SWP and SWPB
Swap data between registers and memory.
Note
These instruction are not supported in ARMv8.Syntax
SWP{B}
{
}
cond
, Rt
,
[Rt2
] Rn
where:
cond
is an optional condition code.
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.
Rt
must not be PC.Rt2
is the source register.
Rt2
can be the same register asRt
.Rt2
must not be PC.Rn
contains the address in memory.
Rn
must be a different register from bothRt
andRt2
.Rn
must not be PC.
Usage
You can use SWP
and SWPB
to
implement semaphores:
Data from memory is loaded into
Rt
.The contents of
Rt2
are saved to memory.If
Rt2
is the same register asRt
, the contents of the register are swapped with the contents of the memory location.
Note
The use of SWP
and SWPB
is deprecated. You can use LDREX
and
STREX
instructions to implement more sophisticated
semaphores.
Availability
These instructions are available in A32.
There are no T32 SWP
or SWPB
instructions.