You copied the Doc URL to your clipboard.

__ldrt intrinsic

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)



Points 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 17. Access widths supported by the __ldrt intrinsic
Instruction[a]Size of data loadedC cast
LDRSBTsigned byte(signed char *)
LDRBTunsigned byte(char *)
LDRSHTsigned halfword(signed short int *)
LDRHTunsigned halfword(short int *)
LDRTword(int *)

[a] Or equivalent.

Return value

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

See also