Library to write x64 Assembly code from Rust, more properly. Designed for the nasm assembler

Overview

x64asm

Library to write x64 Assembly code from Rust, more properly. Designed for the nasm assembler

How to use

let mut f = Formatter::new(false); // false : do not replace spaces by tabulations

f.add_instructions(&mut vec![
    instruction!(/* <mnemonic>, [operands, ...] */),
    // other instructions
]);
f.to_file(&Path::new("output.asm")).unwrap();

Installation

In your "Cargo.toml" file :

[dependencies]
x64asm = { git = "https://github.com/antoninhrlt/x64asm" }

Example

let mut x64asm_formatter = Formatter::new(false);

x64asm_formatter.add_instructions(&mut vec![
    i!(Global, Op::Label("_start".to_string())),

    i!(section!(Text)),
    i!(label!("_start")),
    i!(Mov, reg!(Rax), Op::Literal(1)),
    i!(Mov, reg!(Rdi), Op::Literal(1)),
    i!(Mov, reg!(Rsi), Op::Label("msg".to_string())),
    i!(Mov, reg!(Rdx), Op::Label("msg_len".to_string())),
    i!(Syscall),

    i!(Mov, reg!(Rax), Op::Literal(60)),
    i!(Mov, reg!(Rdi), Op::Literal(0)),
    i!(Syscall),

    i!(section!(Data)),
    i!(label!("msg"), ddirective!(Db), Op::String("Hello world".to_string())),
    i!(label!("msg_len"), ddirective!(Equ), Op::Expression("$ - msg".to_string())),
]);

x64asm_formatter.to_file(&Path::new("example.asm")).unwrap();
Imports for the example
use x64asm::{
    ddirective, ddirective::DefineDirective::*, 
    formatter::Formatter, 
    instruction as i, label,
    mnemonic::Mnemonic::*, 
    operand::Op, 
    reg, register::Register::*, 
    section, section::Section::*,
};

And then, the generated "output.asm" file :

	global _start 
section .text 
_start: 
	mov rax, 1 
	mov rdi, 1 
	mov rsi, msg 
	mov rdx, msg_len 
	syscall 
	mov rax, 60 
	mov rdi, 0 
	syscall
section .data 
msg: db `Hello world` 
msg_len: equ $ - msg 
You might also like...
Write Cross-platform application with React-like decralative UI framework and scalable ECS architecture all in Rust.

bevy_dioxus Dioxus Plugin for Bevy Write Cross-platform application with React-like decralative UI framework and scalable ECS architecture all in Rust

A Write Ahead Log (WAL) implementation in Rust

Okay WAL A write-ahead log (WAL) implementation for Rust. There's The Great Wall, and then there's this: an okay WAL. This crate exposes a WAL that su

Sets of libraries and tools to write applications and libraries mixing OCaml and Rust

Sets of libraries and tools to write applications and libraries mixing OCaml and Rust. These libraries will help keeping your types and data structures synchronized, and enable seamless exchange between OCaml and Rust

A tool for adding new lines to files, skipping duplicates and write in Rust!

anew A tool for adding new lines to files written in Rust. The tool aids in appending lines from stdin to a file, but only if they don't already appea

Write a simple CLI script, that when given a 64-byte encoded string

Write a simple CLI script, that when given a 64-byte encoded string, it finds a suitable 4-byte prefix so that, a SHA256 hash of the prefix combined with the original string of bytes, has two last bytes as 0xca, 0xfe. Script should expect the original content of the string to be passed in hexadecimal format and should return two lines, first being the SHA256 string found and second 4-byte prefix used (in hexadecimal format).

Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.
Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.

Bunt: simple macro-based terminal colors and styles bunt offers macros to easily print colored and formatted text to a terminal. It is just a convenie

That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

📌 This program is designed to translate text into the correct layout when typing is incorrect. 📌 Example ghbdtn - привет Just (by default) pressing

Contains challenges, write-ups, and deployment configurations from b01lersCTF 2023.

CTF Name A template repository for a CTF competition. This is a description of the CTF event. CTFTime Link Structure Challenges are organized by categ

ask.sh: AI terminal assistant that can read and write your terminal directly!
ask.sh: AI terminal assistant that can read and write your terminal directly!

ask.sh: AI terminal assistant that read from & write to your terminal ask.sh is an AI terminal assistant based on OpenAI APIs such as GPT-3.5/4! What'

Owner
Anтo
Sysdev, electronics and embedded systems, 3D. Astronomy. @junon-corp
Anтo
MidenIR for compiling to Miden Assembly from higher-level languages

Miden IR This repository provides a compiler for the Miden VM, specifically for Miden Assembly. It does this by lowering from a higher-level intermedi

Polygon Miden 10 Mar 30, 2023
A visual canvas and virtual machine for writing assembly to build cool things. Create machines and connect them together.

Visual Assembly Canvas A highly visual assembly editor, infinite canvas for wiring blocks and machines together, bytecode virtual machine runnable nat

Phoomparin Mano 31 Oct 11, 2023
A visual canvas and virtual machine for writing assembly to build cool things. Create machines and connect them together.

Visual Assembly Canvas A highly visual assembly editor, infinite canvas for wiring blocks and machines together, bytecode virtual machine runnable nat

Phoomparin Mano 32 Oct 11, 2023
Write simple proc-macros inline with other source code.

script-macro An experimental way to write simple proc-macros inline with other source code. Did you ever end up getting frustrated at the boilerplate

Markus Unterwaditzer 17 Jun 10, 2023
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp 10.4k Jan 4, 2023
Catch Tailwindcss Errors at Compile-Time Before They Catch You, without making any change to your code! Supports overriding, extending, custom classes, custom modifiers, Plugins and many more 🚀🔥🦀

twust Twust is a powerful static checker in rust for TailwindCSS class names at compile-time. Table of Contents Overview Installation Usage Statement

null 15 Nov 8, 2023
colorStyle is a library of styles for command-line text write in Rust.

Colorstyle colorStyle is a library of styles for command-line text. Inspired by flylog/colorstyle (golang) Example let text = colorstyle::green("gre

Code Translation 6 Nov 12, 2022
A Rust program/library to write a Hello World message to the standard output.

hello-world Description hello-world is a Rust program and library that prints the line Hello, world! to the console. Why was this created? This progra

null 0 May 11, 2022
A high-performance Rust library designed to seamlessly integrate with the Discord API.

Rucord - Rust Library for Discord API Interactions Note: This library is currently under development and is not yet recommended for production use. Ov

Coders' Collab 4 Feb 26, 2023
Estratto is a powerful and user-friendly Rust library designed for extracting rich audio features from digital audio signals.

estratto 〜 An Audio Feature Extraction Library estratto is a powerful and user-friendly Rust library designed for extracting rich audio features from

Amber J Blue 5 Aug 25, 2023