https://github.com/dvvcz/dasm
Tiny dynamic assembly library for x86/amd64/rv32i/rv64i
https://github.com/dvvcz/dasm
amd64 assembler code-generator risc-v rust rv32i rv64i x86 x86-64
Last synced: 2 months ago
JSON representation
Tiny dynamic assembly library for x86/amd64/rv32i/rv64i
- Host: GitHub
- URL: https://github.com/dvvcz/dasm
- Owner: DvvCz
- License: gpl-3.0
- Created: 2024-08-31T22:01:38.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-02-12T21:21:59.000Z (4 months ago)
- Last Synced: 2025-03-24T07:04:10.530Z (3 months ago)
- Topics: amd64, assembler, code-generator, risc-v, rust, rv32i, rv64i, x86, x86-64
- Language: Rust
- Homepage:
- Size: 55.7 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
dasm
A tiny, zero dependency assembler that currently supports x86 and amd64.## Note
`dasm` has a goal of acting as a lightweight, simple instructions for compilers.
If you want a higher-level library or something more comprehensive, there's other great solutions like [`Iced`](https://github.com/icedland/iced) or [`dynasm-rs`](https://github.com/CensoredUsername/dynasm-rs).
## How it works
Code generation doesn't have to be hard. This just provides explicit functions for generating instructions.
No abstractions through macros, or some DSL you need to learn. Just functions.**Example**
```rust
use dasm::tier::raw::amd64::*;let rax = 0;
let rsi = 6; // Argument 2
let rdi = 7; // Argument 1let asm = [
&mov_r64_r64(rax, rdi) as &[u8],
&add_r64_r64(rax, rsi),
&ret()
].concat();// Allocate an executable memory block
let mmapped = dasm::mmap::Mmap::exec(&asm)
.expect("Failed to mmap");// Simply cast that memory into a function to call it.
let adder: extern "C" fn(x: u64, y: u64) -> u64 = unsafe { std::mem::transmute(mmapped.as_ptr()) };
assert_eq!(adder(5, 200), 205);
```*There's also an example showcasing a tiny AOT compiled lisp at [`examples/tinylisp`](https://github.com/DvvCz/dasm/tree/master/examples/tinylisp).*
## Why
All of the other solutions are either too big for my usecase (`LLVM`), too complex (`Cranelift`) or have too many abstractions.
Sometimes, you don't need all of that - you just need to write some assembly.
That's what `dasm` is for.*Of course - No shade to any other library. Anyone can use the tool they prefer.*