riscv-codec

Crates.ioriscv-codec
lib.rsriscv-codec
version0.4.0
created_at2025-07-21 21:16:26.211606+00
updated_at2025-08-11 18:05:15.909959+00
descriptionDecode/Encode and Assemble/Disassemble RISC-V instructions
homepage
repositoryhttps://github.com/RebelAndroid/riscv-disassembler
max_upload_size
id1762689
size371,640
Christopher McDevitt (RebelAndroid)

documentation

README

use riscv_codec::{assembly::assemble_line, instruction::Instruction};
fn main() {
    // instruction can be assembled from strings
    let instr: Instruction = assemble_line("addi t0, t1, 1024").unwrap().i();
    // and disassembled
    println!("assembled instruction: {}", instr);

    // instructions can also be decoded from binary
    let instr2 = Instruction::decode(0xe0058513).unwrap();

    // and encoded
    assert_eq!(Instruction::encode(&instr2), 0xe0058513);
}

A crate for working with RISC-V Instructions. Instructions can be encoded and decoded from binary. Basic assembly and disassembly is also supported (Instructions can be converted to and from strings, no support is provided for labels or other features that would be found in a complete assembler).

Supported Instructions

  • RV64I
  • M
  • A
  • F
  • D
  • C
  • Zicsr
  • Zifencei

This crate is (somewhat) well tested. If you find any problems, or think some part of the API could be improved, please make an issue in the github repository.

Commit count: 0

cargo fmt