#assembly #asm #stable

libasm

libasm adds inline assembly to stable rust

3 releases

Uses old Rust 2015

0.1.2 Jan 15, 2018
0.1.1 Jan 14, 2018
0.1.0 Jan 14, 2018

#13 in #stable

27 downloads per month

MIT license

9KB
184 lines

libasm

This is a library to provide inline assembly support for stable Rust.

All that is required to add inline assembly to a project is to create a build script similar to this:

extern crate libasm;

fn main() {
    libasm::parse();
}

This is an example project:

#[macro_use]
extern crate libasm;

lasm! {
    "x86_64-unknown-linux-gnu"
    fn add2 {
        mov %rax, %rdi
        add %rax, %rsi
    }

    "x86_64-pc-windows-msvc"
    fn add2 {
        mov rax, rcx
        add rax, rdx
    }
}

extern "C" {
    fn add2(a: u64, b: u64) -> u64;
}

fn main() {
    let x = unsafe { add2(3, 4) };
    println!("Hello, world! 3 + 4 = {}", x);
}

A lasm! declaration provides a list of target-triple specific assembly functions. It is required to declare your own prototype for the function, as shown here after the lasm! block. If the target-triple being compiled for does not have a matching declaration, you will encounter a linker error unless the implementation comes from somewhere else.

Dependencies

~2MB
~46K SLoC