코딩Coding/Rust연습

Rust연습❤️] Hello from asm__assembly코드 연습

내인생PLUS 2022. 7. 3. 00:41
728x90

Rust Playground에서는 잘 실행 된다. 

인텔 cpu칩인가 보다 ㅠㅠ

 

You can try this example on the playground

 

Rust Playground

 

play.rust-lang.org

.)

 

 

use std::arch::asm;

#[feature(asm)]
fn main() {
    let buf = "Hello from asm!\n";
    let ret: i32;
    unsafe {
        asm!(
            "syscall",
            in("rax") 1, // syscall number
            in("rdi") 1, // fd
            in("rsi") buf.as_ptr(),
            in("rdx") buf.len(),
            out("rcx") _, // clobbered by syscalls
            out("r11") _, // clobbered by syscalls
            lateout("rax") ret,
        );
    }
    println!("write returned: {}", ret);
}

 

 

결과

   Compiling playground v0.0.1 (/playground)
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
 --> src/main.rs:3:1
  |
3 | #[feature(asm)]
  | ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

warning: `playground` (bin "playground") generated 1 warning
    Finished release [optimized] target(s) in 1.40s
     Running `target/release/playground`
Standard Output
Hello from asm!
write returned: 16

 

 

 

 

 

반응형