This intrinsic inserts an instruction of the form LDREX{size} into the instruction stream generated by the compiler. It enables you to load data from memory in your C or C++ code using an LDREX instruction.
unsigned int __ldrex(volatile void *ptr)
Where:
ptrPoints to the address of the data to be loaded from memory. To specify the size of the data to be loaded, cast the parameter to an appropriate integral type.
Table 4.8. Access widths supported by the __ldrex intrinsic
| Instruction | Size of data loaded | C cast |
|---|
LDREXB | unsigned byte | (char *) |
LDREXH | unsigned halfword | (short int *) |
LDREX | word | (int *) |
The __ldrex intrinsic returns the data loaded from the memory address pointed to by ptr.
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.
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.
int foo(void)
{
int loc = 0xff;
return __ldrex((volatile char *)loc);
}
Compiling this code with the command‑line option --device=DLM produces
||foo|| PROC
MOVS r0,#0xff
LDREXB r0,[r0]
BX lr
ENDP