For the context: met unrecognized instruction mnemonic error when naked function uses macro defined in global_asm! · Issue #134960 · rust-lang/rust · GitHub
I'm very new to assembly code, so the answer to this question may be not obvious for me.
Bjorn3 told me assembler state is not guaranteed
There is no guarantee that any assembler state is preserved between inline asm blocks. In fact if we could, we would explicitly prevent you from using this.
does that mean even though the following code compilds with cargo b --target riscv64gc-unknown-none-elf
, it's not a good practice to do so
#![no_std]
core::arch::global_asm!(
r"
.macro LDR rd, rs, off
ld \rd, \off*8(\rs)
.endm
",
);
core::arch::global_asm!(
r"
.globl context_switch
context_switch: // omit code around
LDR s11, a1, 13
",
);
So the only guaranteed way is to put the macro declaration before callsite in the same global_asm statement?
And for the same reason it's also not guaranteed and discouraged to share a macro from global_asm!
with inlined asm!
?