Home > Mobile >  Is there exist "_emit" or equivalent in Rust inline assembly?
Is there exist "_emit" or equivalent in Rust inline assembly?

Time:12-28

In Visual Studio we can generate opcode bytes with the "_emit" directive.

Also, in GCC we can use something like:

asm __volatile__ (".byte 0x12");

Can we do something similar in Rust inline assembly?

CodePudding user response:

Rust's standard inline asm is, unfortunately, basically GAS (with intel syntax by default), so

#![no_main]

#[no_mangle]
unsafe extern "cdecl" fn main() {
    core::arch::asm!(".byte 12h");
}

will generate

main:
  push rax
  .byte 18
  pop rax
  ret

which is the same as in C.

  • Related