【问题标题】:Is there exist "_emit" or equivalent in Rust inline assembly?Is there exist \"_emit\" or equivalent in Rust inline assembly?
【发布时间】:2022-12-27 17:55:45
【问题描述】:

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?

【问题讨论】:

    标签: assembly rust


    【解决方案1】:

    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.

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 2022-12-28
      • 2018-03-07
      • 1970-01-01
      • 2022-12-02
      • 2022-12-27
      相关资源
      最近更新 更多