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. size in LDREX[size] is B for
byte stores or H for halfword stores. If no size
is specified, word stores are performed.
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 15. Access widths supported by the __ldrex intrinsic
Instruction
Size of data loaded
C cast
LDREXB
unsigned byte
(unsigned char *)
LDREXB
signed byte
(signed char *)
LDREXH
unsigned halfword
(unsigned short *)
LDREXH
signed halfword
(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.
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
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.