[][src]Struct lc3::vm::VM

pub struct VM {
    pub register: [i16; 8],
    pub pc: u16,
    pub ir: u16,
    pub supervisor: bool,
    pub priority: u8,
    pub condition: Condition,
    pub mem: [u16; 65536],
}

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

register: [i16; 8]

General purpose registers(R0~R7)

pc: u16

Program Counter

ir: u16

Instruction Register

supervisor: bool

Supervisor mode

priority: u8

Priority Level(PL0~PL7)

condition: Condition

Condition codes

mem: [u16; 65536]

Computer memory

Methods

impl VM[src]

pub fn new() -> VM[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(&mut self, path: &Path) -> 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 psr(&self) -> u16[src]

Calculates, and returns processor state register(PSR) value.

pub fn step<'a, R: Read, W: Write>(
    &mut self,
    input: &'a mut R,
    output: &'a mut W
)
[src]

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

pub fn step_n<'a, R: Read, W: Write>(
    &mut self,
    input: &'a mut R,
    output: &'a mut W,
    n: usize
)
[src]

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

pub fn run<'a, R: Read, W: Write>(
    &mut self,
    input: &'a mut R,
    output: &'a mut W
) -> usize
[src]

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

Returns number of instructions executed.

pub fn run_n<'a, R: Read, W: Write>(
    &mut self,
    input: &'a mut R,
    output: &'a mut W,
    n: usize
) -> usize
[src]

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

Returns the number of instructions executed.

Trait Implementations

impl Clone for VM[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Default for VM[src]

fn default() -> VM[src]

Returns empty, zero-filled virtual machine

Auto Trait Implementations

impl Send for VM

impl Sync for VM

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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.

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

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

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