[−][src]Struct lc3::vm::VM
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: u16Program Counter
ir: u16Instruction Register
supervisor: boolSupervisor mode
priority: u8Priority Level(PL0~PL7)
condition: ConditionCondition 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(&mut self)[src]
Executes next single instruction. This function does not care about the clock enable bit.
pub fn step_n(&mut self, n: usize)[src]
Executes next n instructions. This function does not care about the clock enable bit.
pub fn step_with_hook<F, G>(&mut self, pre_load: F, post_store: G) where
F: FnMut(&mut Self, usize),
G: FnMut(&mut Self, usize), [src]
F: FnMut(&mut Self, usize),
G: FnMut(&mut Self, usize),
Executes next single instruction, with given closures
passed into process_instruction.
This function does not care about the clock enable bit.
pub fn run(&mut self) -> usize[src]
Executes as much as instructions, while the clock enable bit is set to 1.
Returns the number of instructions executed.
Note: This function does not take care of KBSR/DSR, so the VM will run forever if the program calls I/O subroutines.
pub fn run_n(&mut self, 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.
Note: This function does not take care of KBSR/DSR, so the VM will run forever if the program calls I/O subroutines.
pub fn run_with_io<'a>(
&'a mut self,
input: &mut dyn Read,
output: &mut dyn Write
) -> usize[src]
&'a mut self,
input: &mut dyn Read,
output: &mut dyn Write
) -> usize
Shorthand for run_n_with_io(0, input, output)
pub fn run_n_with_io<'a>(
&mut self,
n: usize,
input: &mut dyn Read,
output: &mut dyn Write
) -> usize[src]
&mut self,
n: usize,
input: &mut dyn Read,
output: &mut dyn Write
) -> usize
Executes next n instructions as maximum, while the clock enable bit is set to 1.
If n == 0, runs until it halts.
Additionally, handles input/output with given streams before each steps.
Returns the number of instructions executed.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,