The __ldrex intrinsic lets you load data from memory in your C or C++ code using an LDREX[size] instruction.
size in LDREX[size]
is B for byte loads or H for halfword loads. If no size
is specified, word loads are performed.
Note
This intrinsic is deprecated.
Note
The compiler does not guarantee to preserve the state of the exclusive
monitor. It might generate load and store instructions between the LDREX instruction generated for the __ldrex
intrinsic and the STREX instruction generated for the
__strex intrinsic. Because memory accesses can clear the
exclusive monitor, code using the __ldrex and __strex intrinsics can have unexpected behavior. Where LDREX and STREX instructions are
needed, ARM recommends using embedded assembly.
Syntax
unsigned int __ldrex(volatile void *ptr)
Where:
ptr
points to the address of the data to be loaded from memory. To specify the type of
the data to be loaded, cast the parameter to an appropriate pointer type.
Table 9-8 Access widths that the __ldrex intrinsic supports
Instruction
Size of data loaded
Pointer type
LDREXB
byte
unsigned char *
LDREXB
byte
signed char *
LDREXH
halfword
unsigned short *
LDREXH
halfword
signed short *
LDREX
word
int *
Return value
The __ldrex intrinsic returns the data loaded from the memory address
pointed to by ptr.
Errors
The compiler does not recognize the __ldrex intrinsic when compiling for a
target that does not support the LDREX instruction. The compiler generates
either a warning or an error in this case, depending on the source language:
In C code: Warning: #223-D: function "__ldrex" declared implicitly.
In C++ code: Error: #20: identifier "__ldrex" is undefined.
The __ldrex intrinsic does not support access to doubleword data. The
compiler generates an error if you specify an access width that is not supported.
Example
int foo(void)
{
int loc = 0xff;
return __ldrex((volatile char *)loc);
}
Compiling this code with the command-line option --cpu=6k produces
||foo|| PROC
MOV r0,#0xff
LDREXB r0,[r0]
BX lr
ENDP
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.