Search code examples
rustraspberry-piarm

Inline ARM assembly instructions


I wanted to run some ARM assembly instructions in my rust code since I am targeting the raspberry pi. The problem is rust complains about the following:

unsafe {
    asm!("ldr r0, =0x3f200000");
}

I get error: Only valid when first operand is register. But r0 is an ARM register (?).

Furthermore, instead of using the raw addresses I would like to use constants, but I cannot get that to work either, and after reading the rust documentation on this I still cannot wrap my head around the supposed syntax.


Solution

  • r0 is a valid register name in Aarch32 mode. If you are running Rust in Aarch64 mode, you should use ldr x0, =0x3f200000 or ldr w0, =0x3f200000