| |||
| Home > ARM and Thumb Instructions > Memory access instructions > SWP and SWPB | |||
Swap data between registers and memory.
SWP{B}{cond}Rt,Rt2, [Rn]
where:
condis an optional condition code.
Bis
an optional suffix. If B is present, a byte
is swapped. Otherwise, a 32-bit word is swapped.
Rtis the destination register. must
not be PC.Rt
Rt2is the source register. can
be the same register as Rt2. Rt must
not be PC.Rt2
Rncontains the address in memory. must
be a different register from both Rn and Rt. Rt2 must
not be PC.Rn
You can use SWP and SWPB to implement
semaphores:
Data from memory is loaded into .Rt
The contents of is
saved to memory.Rt2
If is
the same register as Rt2,
the contents of the register is swapped with the contents of the
memory location.Rt
The use of SWP and SWPB is deprecated
in ARMv6 and above. You can use LDREX and STREX instructions
to implement more sophisticated semaphores in ARMv6 and above.
These ARM instructions are available in all versions of the ARM architecture.
There are no Thumb SWP or SWPB instructions.