I am trying to use C variables in assembly. The purpose is to read a 32bit memory and assign it to a C variable.
uint32_t ASMRegRd32(uint32_t addr) {
uint32_t data;
asm volatile (
"ldr %0, [%1]" "\n"
: "=r" (data)
: "r"(addr)
);
return data;
}
Sadly being on AARCH64, above ldr
instruction is returning a 64bit value, as compiler is choosing a 64bit operand Xt.
How can I restrict it to use a 32bit operand?
Should this work?
ldr w0, [%1];
mov %0, w0;