Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samsa1/write_x86_64
Library to help writting X86_64 assembly in rust
https://github.com/samsa1/write_x86_64
Last synced: about 8 hours ago
JSON representation
Library to help writting X86_64 assembly in rust
- Host: GitHub
- URL: https://github.com/samsa1/write_x86_64
- Owner: samsa1
- License: mit
- Created: 2022-10-20T10:50:13.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-03T15:20:59.000Z (over 1 year ago)
- Last Synced: 2024-03-22T20:22:12.738Z (8 months ago)
- Language: Rust
- Size: 109 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# write_x86_64 rust crate
## Objective
This crate is written in the purpose of helping people implement a x86_64 assembly backend for a compiler in rust.
Thus, this crate implements data structures to write simple x86_64 instructions but also type check those instructions.## Usage
Generate a Hello World program for x86_64 macOS (also works on Linux)
```rust
use write_x86_64::*;fn main() {
let file_name = "asm_file.s";let text_ss = Segment::label(new_label("main"))
+ pushq(reg!(RBP))
+ leaq(lab!(new_label("my_string")), RDI)
+ call(reg::Label::printf())
+ leaq(lab!(new_label("my_string2")), RDI)
+ call(reg::Label::printf())
+ xorq(reg!(RAX), reg!(RAX))
+ popq(RBP)
+ ret();let data_ss = Data::label(new_label("my_string"))
+ data::dasciz("Hello".to_string())
+ Data::label(new_label("my_string2"))
+ data::dasciz(" World\\n".to_string());let file = file::File {
globl: Some(new_label("main")),
text_ss,
data_ss,
};file.print_in(file_name).unwrap();
}
```## Contributing
Contribution are welcomed, you can also ask to add some
instructions if you are using this crate and would want more
instructions available.## Future work
We are currently trying to implement DWARF debug symbols.
Any contribution, testing, comment are welcomed.## Project using this crate:
- A compiler for a subset of Rust : https://github.com/samsa1/SamRustCompiler