You copied the Doc URL to your clipboard.

8.5.3. Example of LDREX and STREX usage

The following 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  R1, R0, [LockAddr]; try and claim the lock
    CMPEQ R0, #0               ; did this succeed?
    BNE try                    ; no – try again. . .
; yes – we have the lock
Was this page helpful? Yes No