
git-subtree-dir: compiler/rustc_codegen_gcc git-subtree-mainline:ae90dcf020
git-subtree-split:afae271d5d
66 lines
1.1 KiB
Rust
66 lines
1.1 KiB
Rust
// Compiler:
|
|
//
|
|
// Run-time:
|
|
// status: 0
|
|
|
|
#![feature(asm, global_asm)]
|
|
|
|
global_asm!("
|
|
.global add_asm
|
|
add_asm:
|
|
mov rax, rdi
|
|
add rax, rsi
|
|
ret"
|
|
);
|
|
|
|
extern "C" {
|
|
fn add_asm(a: i64, b: i64) -> i64;
|
|
}
|
|
|
|
fn main() {
|
|
unsafe {
|
|
asm!("nop");
|
|
}
|
|
|
|
let x: u64;
|
|
unsafe {
|
|
asm!("mov $5, {}",
|
|
out(reg) x,
|
|
options(att_syntax)
|
|
);
|
|
}
|
|
assert_eq!(x, 5);
|
|
|
|
let x: u64;
|
|
let input: u64 = 42;
|
|
unsafe {
|
|
asm!("mov {input}, {output}",
|
|
"add $1, {output}",
|
|
input = in(reg) input,
|
|
output = out(reg) x,
|
|
options(att_syntax)
|
|
);
|
|
}
|
|
assert_eq!(x, 43);
|
|
|
|
let x: u64;
|
|
unsafe {
|
|
asm!("mov {}, 6",
|
|
out(reg) x,
|
|
);
|
|
}
|
|
assert_eq!(x, 6);
|
|
|
|
let x: u64;
|
|
let input: u64 = 42;
|
|
unsafe {
|
|
asm!("mov {output}, {input}",
|
|
"add {output}, 1",
|
|
input = in(reg) input,
|
|
output = out(reg) x,
|
|
);
|
|
}
|
|
assert_eq!(x, 43);
|
|
|
|
assert_eq!(unsafe { add_asm(40, 2) }, 42);
|
|
}
|