102
SAM4CP [DATASHEET]
43051E–ATPL–08/14
Examples
MOV R1, #0x1 ; Initialize the ‘lock taken’ value try
LDREX R0, [LockAddr] ; Load the lock value
CMP R0, #0 ; Is the lock free
ITT EQ ; IT instruction for STREXEQ and CMPEQ
STREXEQ R0, R1, [LockAddr] ; Try and claim the lock
CMPEQ R0, #0 ; Did this succeed
BNE try ; No – try again
.... ; Yes – we have the lock
12.6.4.9 CLREX
Clear Exclusive.
Syntax
CLREX{
cond
}
where:
cond
is an optional condition code, see
“Conditional Execution”
.
Operation
Use CLREX to make the next STREX, STREXB, or STREXH instruction write 1 to its destination register and fail to per-
form the store. It is useful in exception handler code to force the failure of the store exclusive if the exception occurs
between a load exclusive instruction and the matching store exclusive instruction in a synchronization operation.
See
“Synchronization Primitives”
for more information.
Condition Flags
These instructions do not change the flags.
Examples
CLREX