6 #![feature(asm_const, asm_sym)]
8 use std::arch::{asm, global_asm};
19 fn add_asm(a: i64, b: i64) -> i64;
22 pub unsafe fn mem_cpy(dst: *mut u8, src: *const u8, len: usize) {
25 inout("rdi") dst => _,
26 inout("rsi") src => _,
27 inout("rcx") len => _,
28 options(preserves_flags, nostack)
49 asm!("mov {input}, {output}",
51 input = in(reg) input,
69 asm!("mov {output}, {input}",
71 input = in(reg) input,
77 // check inout(reg_class) x
86 // check inout("reg") x
97 // inout(class) x => y
102 let mut rem: u64 = 0;
106 inout("eax") x => res,
123 // check const (ATT syntax)
135 extern "C" fn foo() -> u64 { 42 }
138 asm!("call {}", sym foo, lateout("rax") x);
142 // check sym fn (ATT syntax)
145 asm!("call {}", sym foo, lateout("rax") x, options(att_syntax));
150 static FOO: u64 = 42;
153 asm!("mov {1}, qword ptr [rip + {0}]", sym FOO, lateout(reg) x);
157 // check sym static (ATT syntax)
160 asm!("movq {0}(%rip), {1}", sym FOO, lateout(reg) x, options(att_syntax));
164 assert_eq!(unsafe { add_asm(40, 2) }, 42);
166 let array1 = [1u8, 2, 3];
167 let mut array2 = [0u8, 0, 0];
169 mem_cpy(array2.as_mut_ptr(), array1.as_ptr(), 3);
171 assert_eq!(array1, array2);