#mips #assembly #disassembly #machine #u32 #return #instructions

MIPS_disassembly

Takes MIPS machine code and return MIPS assembly

8 releases

0.1.7 Oct 4, 2024
0.1.6 Oct 3, 2024
0.1.2 Aug 31, 2024

#2 in #u32

Download history 330/week @ 2024-08-26 19/week @ 2024-09-02 66/week @ 2024-09-16 27/week @ 2024-09-23 540/week @ 2024-09-30 74/week @ 2024-10-07 47/week @ 2024-10-14

423 downloads per month

MIT license

22KB
520 lines

MIPS_disassembly

This crate dissembles u32 into mips assembly

Examples

Simple example

use MIPS_disassembly::get_disassembly;

let instr: u32 = 0x24a50001;
let instr_asm: String = get_disassembly(instr);
assert_eq!(instr_asm, "ADDIU $a1, $a1, 1".to_string())

Example using the advance version

use MIPS_disassembly::get_disassembly_adv

let mut sym_tab: HashMap<u32, String> = HashMap::new();
sym_tab.insert(0x00000108, "decode_if".into());
let instr: u32 = 0x11a0001a;
let instr_adrs: u32 = 0x9c;
assert_eq!(
    "BEQ $t5, $zero, 26 <decode_if>",
    get_disassembly_adv(
        instr,
        instr_adrs,
        &sym_tab,
        &MipsDisassemblyOptions::new(true, true)
    )
);

Example of the pseudo instruction option

use MIPS_disassembly::get_disassembly_adv;
use MIPS_disassembly::MipsDisassemblyOptions;
use std::collections::HashMap;

let instr: u32 = 0x0;
assert_eq!(
    "NOP",
    get_disassembly_adv(
        instr,
        0x0,
        &HashMap::new(),
        &MipsDisassemblyOptions::new(true, true)
    )
);
assert_eq!(
    "SLL $zero, $zero, $zero",
    get_disassembly_adv(
        instr,
        0x0,
        &HashMap::new(),
        &MipsDisassemblyOptions::new(true, false)
    )
);

Supported instructions

  • SLL
  • SRL
  • SRA
  • SLLV
  • SRLV
  • SRAV
  • JR
  • JALR
  • SYSCALL
  • ADD
  • ADDU
  • SUB
  • SUBU
  • AND
  • OR
  • XOR
  • NOR
  • SLT
  • SLTU
  • BLTZ
  • BGEZ
  • BLTZAL
  • BGEZAL
  • J
  • JAL
  • BEQ
  • BNE
  • BLEZ
  • BGTZ
  • ADDI
  • ADDIU
  • SLTI
  • SLTIU
  • ANDI
  • ORI
  • XORI
  • LUI
  • LB
  • LH
  • LWL
  • LW
  • LBU
  • LHU
  • LWR
  • SB
  • SH
  • SWL
  • SW
  • SWR

Supported pseudo instructions

  • NOP
  • B
  • BAL
  • MOVE
  • JALR (omits $rd if its $31/$ra)

No runtime deps