Mipsasm

Struct Mipsasm 

Source
pub struct Mipsasm<'a> { /* private fields */ }
Expand description

An instance of the assembler/disassembler

Implementations§

Source§

impl<'a> Mipsasm<'a>

Source

pub fn new() -> Mipsasm<'a>

Create a new Mipsasm instance.

Sets the base address to 0 and the debug flag to false.

Source

pub fn base(&mut self, addr: u32) -> &mut Mipsasm<'a>

Set the base address for the assembler.

§Examples
use mipsasm::Mipsasm;

let mut mipsasm = Mipsasm::new();
mipsasm.base(0x8000_0000);
Source

pub fn symbols(&mut self, syms: HashMap<&'a str, u32>) -> &mut Mipsasm<'a>

Provides the assembler with a set of symbols.

§Examples
use mipsasm::Mipsasm;
use std::collections::HashMap;

let mut mipsasm = Mipsasm::new();
mipsasm.symbols(HashMap::from_iter(vec![("foo", 0x8000_0000)]));
Source

pub fn debug(&mut self) -> &mut Mipsasm<'a>

Set the debug flag for the assembler.

When debug is set to true, the disassembler will print instructions with all extra whitespace stripped. This is used for testing and will most likely not be useful for other purposes.

§Examples
use mipsasm::Mipsasm;

let mut mipsasm = Mipsasm::new();
mipsasm.debug();
Source

pub fn assemble(&self, input: &str) -> Result<Vec<u32>, Vec<ParserError>>

Assembles a set of MIPS assembly instructions.

§Examples
use mipsasm::Mipsasm;
let mut mipsasm = Mipsasm::new();
let instructions = mipsasm.assemble("
   add $t0, $t1, $t2
  addi $t0, $t1, 0x1234
");
Source

pub fn disassemble(&self, input: &[u32]) -> Vec<String>

Disassembles a set of MIPS instructions.

§Examples
use mipsasm::Mipsasm;

let mut mipsasm = Mipsasm::new();
let instructions = mipsasm.disassemble(&[0x00850018]);
assert_eq!(instructions, vec!["mult       $a0, $a1"]);

Trait Implementations§

Source§

impl<'a> Default for Mipsasm<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Mipsasm<'a>

§

impl<'a> RefUnwindSafe for Mipsasm<'a>

§

impl<'a> Send for Mipsasm<'a>

§

impl<'a> Sync for Mipsasm<'a>

§

impl<'a> Unpin for Mipsasm<'a>

§

impl<'a> UnwindSafe for Mipsasm<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.