Function mosis::linear_sweep [−][src]
pub fn linear_sweep<'a>(
bytes: &'a [u8]
) -> Box<dyn Iterator<Item = Result<Instruction, MOSISError>> + 'a>
Iterates over a slice of bytes, performing a linear sweep disassembly to MOSIS
Instruction
s.
Iterate over a byte slice, disassembling as big endian u16
s, yielding Instruction
s or
MOSISError
s when disassembly fails.
Examples
use mosis::{linear_sweep, Instruction::*, Register::*}; let bytes = &[0x23, 0x12, 0x2a, 0x34, 0x3a, 0x98, 0x3f, 0xed]; let mut x = linear_sweep(bytes); assert_eq!(x.next(), Some(Ok(Add { dst: R3, x: R1, y: R2 }))); assert_eq!(x.next(), Some(Ok(Add { dst: Ra, x: R3, y: R4 }))); assert_eq!(x.next(), Some(Ok(Sub { dst: Ra, x: R9, y: R8 }))); assert_eq!(x.next(), Some(Ok(Sub { dst: Rf, x: Re, y: Rd }))); assert_eq!(x.next(), None);
use mosis::linear_sweep; for instruction in linear_sweep(bytes) { println!("{}", instruction.unwrap()); }