Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antoninhrlt/x64asm
Library to write x64 Assembly code from Rust, more properly. Designed for the nasm assembler
https://github.com/antoninhrlt/x64asm
assembly assembly-language nasm rust x64 x86-64
Last synced: 27 days ago
JSON representation
Library to write x64 Assembly code from Rust, more properly. Designed for the nasm assembler
- Host: GitHub
- URL: https://github.com/antoninhrlt/x64asm
- Owner: antoninhrlt
- License: mit
- Created: 2022-04-12T17:10:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T22:40:25.000Z (almost 2 years ago)
- Last Synced: 2024-09-30T06:06:45.008Z (about 1 month ago)
- Topics: assembly, assembly-language, nasm, rust, x64, x86-64
- Language: Rust
- Homepage: https://docs.rs/x64asm/latest/x64asm
- Size: 32.2 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# x64asm
Library to write x64 Assembly code from Rust, more properly. Designed for the nasm assembler## How to use
```rust
let instructions = vec![
i!(/* , [operands, ...] */),
// other instructions
];let code = instructions.to_assembly(/*separator (space or tab)*/);
// Writes to a file
let mut stream = File::create(&Path::new("output.asm")).unwrap();
write!(stream, "{}", code).unwrap();
```## Installation
In your "Cargo.toml" file :
```toml
[dependencies]
x64asm = "*"
```Check the current version on [crates.io](https://crates.io/crates/x64asm)
## Example
```rust
let instructions = vec![
i!(Global, oplabel!("_start")),i!(section!(Text)),
i!(label!("_start")),
i!(Mov, reg!(Rax), Op::Literal(1)),
i!(Mov, reg!(Rdi), Op::Literal(1)),
i!(Mov, reg!(Rsi), oplabel!("msg")),
i!(Mov, reg!(Rdx), oplabel!("msg_len")),
i!(Syscall),i!(Mov, reg!(Rax), Op::Literal(60)),
i!(Mov, reg!(Rdi), Op::Literal(0)),
i!(Syscall),
i!(section!(Data)),
i!(label!("msg"), dd!(Db), opstring!("Hello world")),
i!(label!("msg_len"), dd!(Equ), opexpr!("$ - msg")),
];let code = instructions.to_assembly(Separator::Space);
let mut stream = File::create(&Path::new("output.asm")).unwrap();
write!(stream, "{}", code).unwrap();
```Imports for the example
```rust
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;use x64asm::convert::{ ToAssembly, Separator };
use x64asm::macros::*;
```And then, the generated "output.asm" file :
```asm
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
```## Notes
Originally inspired by [GregoryComer/rust-x86asm](https://github.com/GregoryComer/rust-x86asm).