#jit #dynasm #assembler #dynasmrt #dynasm-rs


A simple runtime for assembling code at runtime. Combined with the plugin crate dynasm it can be used to write JIT compilers easily.

25 releases (1 stable)

1.0.0 Jul 20, 2020
0.7.1 Jul 1, 2020
0.7.0 Jun 30, 2020
0.6.0 Feb 24, 2020
0.0.6 Oct 27, 2016

#1 in Emulators

Download history 2371/week @ 2020-06-09 1629/week @ 2020-06-16 2559/week @ 2020-06-23 2380/week @ 2020-06-30 2029/week @ 2020-07-07 2696/week @ 2020-07-14 2391/week @ 2020-07-21 2141/week @ 2020-07-28 2758/week @ 2020-08-04 2423/week @ 2020-08-11 4241/week @ 2020-08-18 2692/week @ 2020-08-25 2354/week @ 2020-09-01 3478/week @ 2020-09-08 2719/week @ 2020-09-15 2691/week @ 2020-09-22

11,457 downloads per month
Used in 36 crates (9 directly)

MPL-2.0 license

3.5K SLoC

A Dynamic assembler written in Rust for Rust.

The purpose of this tool is to ease the creation of programs that require run-time assembling.

It is currently in beta, meaning that everything is operational, but some APIs might change in the future.

The tool currently requires a nightly toolchain to build with, but will transition to stable at rust 1.45.

Build Status

##dynasm-rs on irc.freenode.net


  • Fully integrated in the rust toolchain, no other tools necessary.
  • The assembly is optimized into a series of Vec.push and Vec.extend statements.
  • Errors are almost all diagnosed at compile time in a clear fashion.
  • Write the to be generated assembly inline in nasm-like syntax using a simple macro.


Documentation. Release notes.

Architecture support

  • Supports the x64/x86 instruction sets in long and protected mode with every AMD/Intel/VIA extension except for AVX-512.
  • Supports the aarch64 instruction set up to ARMv8.4 except for SVE instructions. The development of this assembler backend has been generously sponsored by the awesome folks at Wasmer!


use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi};

use std::{io, slice, mem};
use std::io::Write;

fn main() {
    let mut ops = dynasmrt::x64::Assembler::new().unwrap();
    let string = "Hello World!";

        ; .arch x64
        ; ->hello:
        ; .bytes string.as_bytes()

    let hello = ops.offset();
        ; .arch x64
        ; lea rcx, [->hello]
        ; xor edx, edx
        ; mov dl, BYTE string.len() as _
        ; mov rax, QWORD print as _
        ; sub rsp, BYTE 0x28
        ; call rax
        ; add rsp, BYTE 0x28
        ; ret

    let buf = ops.finalize().unwrap();

    let hello_fn: extern "win64" fn() -> bool = unsafe { mem::transmute(buf.ptr(hello)) };


pub extern "win64" fn print(buffer: *const u8, length: u64) -> bool {
        .write_all(unsafe { slice::from_raw_parts(buffer, length as usize) })


This project is heavily inspired by Dynasm


The development of the Aarch64 assembler backend has been sponsored by Wasmer.


Mozilla Public License, v. 2.0, see LICENSE

Copyright 2016 CensoredUsername

Guaranteed to be working compiler versions

This project used to be a compiler plugin, so for old compilers, here's a list of which version of dynasm was guaranteed to work with which compiler. As the project has since transitioned to be a proc macro, this is not relevant for modern versions of the compiler.

  • v0.2.0: rustc 1.27.0-nightly (ac3c2288f 2018-04-18)
  • v0.2.1: rustc 1.28.0-nightly (a1d4a9503 2018-05-20)
  • v0.2.3: rustc 1.31.0-nightly (96cafc53c 2018-10-09)


~25K SLoC