[][src]Struct lc3::VM

pub struct VM<H = TrivialHandler> where
    H: InstructionHandler
{ pub state: VMState, pub context: H::Context, }

A single LC-3 virtual machine. Each machines processes instructions in memory, handling appropriate I/O requests in device registers.

Note: memory-mapped I/O registers are not implemented as separated fields. The VM will treat device registers as normal words in the mem.

Note: Currently interrupts are not implemented.

Fields

state: VMStatecontext: H::Context

Instruction handler context

Implementations

impl<H> VM<H> where
    H: InstructionHandler,
    H::Err: Debug
[src]

pub fn new(initial_context: H::Context) -> VM<H>[src]

Returns a new, initialized LC-3 machine, with default operating system loaded.

pub fn load_u8(&mut self, program: &[u8])[src]

Loads a program from raw u8 slice(generally, file contents).

Panics

This function panics if program slice's length is not even or less than two(invalid header).

pub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>[src]

Loads a program from given path of file.

Panics

This function panics if file contents' length is not even or less than two(invalid header).

pub fn load_u16(&mut self, entry: usize, program: &[u16])[src]

Loads a program from u16 slice from entry point given, and set pc to it. All other load_* wrappers should convert given input program into u16 slice, and pass it to this method at the last.

Panics

This function panics if program size exceeds machine memory range. (entry + program.len() >= 65536)

pub fn step(&mut self) -> Result<(), H::Err>[src]

Executes next single instruction. This function does not care about the clock enable bit.

pub fn step_n(&mut self, n: usize) -> Result<(), H::Err>[src]

Executes next n instructions. This function does not care about the clock enable bit.

pub fn run(&mut self) -> Result<usize, H::Err>[src]

Executes as much as instructions, while the clock enable bit is set to 1.

Returns number of instructions executed if vm was executed without errors until termination, or returns error immediately when error has occurred.

pub fn run_n(&mut self, n: usize) -> Result<usize, H::Err>[src]

Executes next n instructions at maximum, while the clock enable bit is set to 1.

Returns number of instructions executed if vm was executed without errors until termination, or returns error immediately when error has occurred.

Trait Implementations

impl<H: Clone> Clone for VM<H> where
    H: InstructionHandler,
    H::Context: Clone
[src]

impl Default for VM<TrivialHandler>[src]

Auto Trait Implementations

impl<H> RefUnwindSafe for VM<H> where
    <H as InstructionHandler>::Context: RefUnwindSafe

impl<H> Send for VM<H> where
    <H as InstructionHandler>::Context: Send

impl<H> Sync for VM<H> where
    <H as InstructionHandler>::Context: Sync

impl<H> Unpin for VM<H> where
    <H as InstructionHandler>::Context: Unpin

impl<H> UnwindSafe for VM<H> where
    <H as InstructionHandler>::Context: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.