riscv-codec 0.4.0

Decode/Encode and Assemble/Disassemble RISC-V instructions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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);

    let instr2 = assemble_line("fcvt.lu.s zero,ft0,rne").unwrap().i();
    println!("assembled instruction: {}", instr2);
}