https://github.com/coder543/libasm
https://github.com/coder543/libasm
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/coder543/libasm
- Owner: coder543
- License: mit
- Created: 2018-01-14T22:37:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T00:40:11.000Z (almost 8 years ago)
- Last Synced: 2025-08-16T11:55:48.505Z (3 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 61
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```rust
extern crate libasm;
fn main() {
libasm::parse();
}
```
[This is an example project:](https://github.com/coder543/asmtest)
```rust
#[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.