Struct VM

Source
pub struct VM<H = TrivialHandler>{
    pub state: VMState,
    pub context: H::Context,
}
Expand description

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: VMState§context: H::Context

Instruction handler context

Implementations§

Source§

impl<H> VM<H>

Source

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

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

Source

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

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).

Source

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

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).

Source

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

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)

Source

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

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

Source

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

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

Source

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

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.

Source

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

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§

Source§

impl<H> Clone for VM<H>

Source§

fn clone(&self) -> VM<H>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for VM<TrivialHandler>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<H> Freeze for VM<H>

§

impl<H> RefUnwindSafe for VM<H>

§

impl<H> Send for VM<H>

§

impl<H> Sync for VM<H>

§

impl<H> Unpin for VM<H>

§

impl<H> UnwindSafe for VM<H>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.