pub struct VM<H = TrivialHandler>where
H: InstructionHandler,{
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>
impl<H> VM<H>
Sourcepub fn new(initial_context: H::Context) -> VM<H>
pub fn new(initial_context: H::Context) -> VM<H>
Returns a new, initialized LC-3 machine, with default operating system loaded.
Sourcepub fn load_u8(&mut self, program: &[u8])
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).
Sourcepub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
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).
Sourcepub fn load_u16(&mut self, entry: usize, program: &[u16])
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
)
Sourcepub fn step(&mut self) -> Result<(), H::Err>
pub fn step(&mut self) -> Result<(), H::Err>
Executes next single instruction. This function does not care about the clock enable bit.
Sourcepub fn step_n(&mut self, n: usize) -> Result<(), H::Err>
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.