This intrinsic inserts an assembly language instruction of the form LDR{size}T into the instruction stream generated by the compiler. It enables you to load data from memory in your C or C++ code using an LDRT instruction.
unsigned int __ldrt(const 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.9. Access widths supported by the __ldrt intrinsic
| Instruction[1] | Size of data loaded | C cast |
|---|
LDRSBT | signed byte | (signed char *) |
LDRBT | unsigned byte | (char *) |
LDRSHT | signed half word | (signed short int *) |
LDRHT | unsigned halfword | (short int *) |
LDRT | word | (int *) |
The __ldrt intrinsic returns the data loaded from the memory address pointed to by ptr.
The compiler does not recognize the __ldrt intrinsic when compiling for a target that does not support the LDRT instruction. The compiler generates either a warning or an error in this case.
The __ldrt 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 __ldrt((const volatile int *)loc);
}
Compiling this code with the default options produces:
||foo|| PROC
MOV r0,#0xff
LDRBT r1,[r0],#0
MOV r2,#0x100
LDRBT r0,[r2],#0
ORR r0,r1,r0,LSL #8
BX lr
ENDP