A Rust implementation of a RISC-V (RV32IM) assembler with both a library and CLI tool.
This workspace contains:
- A RISC-V assembler library (
riscv_asm) that provides core functionality for assembling RISC-V code - A command-line interface (
cli) for using the assembler with files
- Support for the complete RV32I base instruction set
- Support for the RV32M extension (multiplication and division instructions)
- Common assembler directives (
.word,.byte,.align, etc.) - Symbol table with forward reference resolution
- Multiple output formats (binary, Intel HEX, and text)
- Detailed error reporting
riscv-assembler/
├── crates/
│ └── riscv_asm/ # Core assembler library
│ ├── src/ # Library source code
│ └── Cargo.toml # Library manifest
├── bins/
│ └── cli/ # Command-line interface
│ ├── src/ # CLI source code
│ └── Cargo.toml # CLI manifest
└── Cargo.toml # Workspace manifest
- Rust toolchain (1.70.0 or newer)
Clone this repository and build using Cargo:
git clone https://github.com/developeruche/riscv-assembler.git
cd riscv-assembler
cargo build --releaseThe CLI binary will be available at target/release/cli.
To use the riscv_asm library in your own project, add it to your Cargo.toml:
[dependencies]
riscv_asm = { git = "https://github.com/developeruche/riscv-assembler.git" }# Assemble a file
cli input.s -o output.bin
# Generate Intel HEX format
cli input.s --format hex
# Show verbose output
cli input.s --verboseuse riscv_asm::assembler::assemble;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let source = r#"
.text
addi x1, x0, 42
"#;
let output = assemble(source)?;
println!("Generated {} bytes of machine code", output.size);
Ok(())
}- For detailed library documentation, check the library README
- For CLI usage information, see the CLI README
- A good cheat sheet is available at https://projectf.io/posts/riscv-cheat-sheet/
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.