The Cortex-M4 Instruction Set
ARM DUI 0553A
Copyright © 2010 ARM. All rights reserved.
3-37
ID121610
Non-Confidential
Restrictions
In these instructions:
•
do not use PC
•
do not use SP for
Rd
and
Rt
•
for
STREX
,
Rd
must be different from both
Rt
and
Rn
•
the value of
offset
must be a multiple of four in the range 0-1020.
Condition flags
These instructions do not change the flags.
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.