Level Two Interface
ARM DDI 0301H
Copyright © 2004-2009 ARM Limited. All rights reserved.
8-7
ID012310
Non-Confidential, Unrestricted Access
8.2.2
Store-exclusive instruction
Store-exclusive performs a conditional store to memory. The store only takes place if the
physical address is tagged as exclusive-access for the requesting processor. This operation
returns a status value. If the store updates memory the return value is 0, otherwise it is 1. In both
cases, the physical address is no longer tagged as exclusive-access for any processor.
8.2.3
Example of LDREX and STREX usage
This is an example of typical usage. Suppose you are trying to claim a lock:
Lock address
:
LockAddr
Lock free
:
0x00
Lock taken
:
0xFF
MOV
R1, #0xFF
; load the ‘lock taken’ value
try LDREX
R0, [LockAddr]
; load the lock value
CMP
R0, #0
; is the lock free?
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
The typical case, where the lock is free and you have exclusive-access, is six instructions.