'How do I write inline assembly for `"={ecx}"(features)` in stable Rust?
I have the following inline assembly which used to work in Rust, but it seems there has been some changes to the syntax, and it throws error at "={ecx}(features) with the message expected type. How can I rewrite this in new assembly syntax?
use std::arch::asm;
let features: u32;
unsafe {
asm!("mov eax, 1
cpuid"
: "={ecx}"(features)
:
: "eax"
: "intel"
);
}
let support: u32 = (features >> 25) & 1;
Solution 1:[1]
Try this:
use std::arch::asm;
fn main() {
let features: u32;
unsafe {
asm!("mov eax, 1",
"push rbx",
"cpuid",
"pop rbx",
out("ecx") features,
out("eax") _,
out("edx") _,
);
}
println!("features: {:x}", features);
}
Note that you are not allowed to clobber ebx since it is used internally by LLVM, so you need to save and restore it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
