【发布时间】:2021-06-07 11:51:38
【问题描述】:
我正在编写 Rust 代码,需要获取当前存储在“ebx”寄存器 (x86) 中的值。
我的代码 [0] 如下所示:
#![feature(asm)]
fn main() {
let ebx: u32;
unsafe { asm!("", out("ebx") ebx) };
println!("current value of register ebx is: {}", ebx);
}
rustc 1.54.0-nightly 的错误代码是:
invalid register `ebx`: rbx is used internally by LLVM and cannot be used as an operand for inline asm
我发现的唯一可行的解决方法是传统方式:
unsafe {
llvm_asm!("" : "={ebx}"(ebx) : :);
}
有没有办法通过新的asm! 宏实现所需的功能?
PS:由于我的研究,我发现了这个:https://github.com/rust-lang/rust/pull/84658。但它仍然没有提供一个好的简单的解决方案。
【问题讨论】:
标签: rust