You copied the Doc URL to your clipboard.

LDREX

Load Register Exclusive.

Syntax

LDREX{cond} Rt, [Rn {, #offset}]

LDREXB{cond} Rt, [Rn]

LDREXH{cond} Rt, [Rn]

LDREXD{cond} Rt, Rt2, [Rn]

where:

cond
is an optional condition code.
Rt
is the register to load.
Rt2
is the second register for doubleword loads.
Rn
is the register on which the memory address is based.
offset
is an optional offset applied to the value in Rn. offset is permitted only in 32-bit T32 instructions. If offset is omitted, an offset of zero is assumed.

Operation

LDREX loads data from memory.

  • If the physical address has the Shared TLB attribute, LDREX tags the physical address as exclusive access for the current processor, and clears any exclusive access tag for this processor for any other physical address.
  • Otherwise, it tags the fact that the executing processor has an outstanding tagged physical address.

LDREXB and LDREXH zero extend the value loaded.

Restrictions

PC must not be used for any of Rt, Rt2, or Rn.

For A32 instructions:

  • SP can be used but use of SP for any of Rt, or Rt2 is deprecated.
  • For LDREXD, Rt must be an even numbered register, and not LR.
  • Rt2 must be R(t+1).
  • offset is not permitted.

For T32 instructions:

  • SP can be used for Rn, but must not be used for Rt or Rt2.
  • For LDREXD, Rt and Rt2 must not be the same register.
  • The value of offset can be any multiple of four in the range 0-1020.

Usage

Use LDREX and STREX to implement interprocess communication in multiple-processor and shared-memory systems.

For reasons of performance, keep the number of instructions between corresponding LDREX and STREX instructions to a minimum.

Note

The address used in a STREX instruction must be the same as the address in the most recently executed LDREX instruction.

Architectures

These 32-bit instructions are available in A32 and T32.

The LDREXD instruction is not available in the Arm®v7‑M architecture.

There are no 16-bit versions of these instructions in T32.

Examples

    MOV r1, #0x1                ; 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
Was this page helpful? Yes No