diff --git a/src/vm/instruction.rs b/src/vm/instruction.rs index 9883d8b..c4216d9 100644 --- a/src/vm/instruction.rs +++ b/src/vm/instruction.rs @@ -118,7 +118,7 @@ fn op_trap(vm: &mut VM, instr: u16) { 0x22 => todo!("PUTS"), 0x23 => todo!("IN"), 0x24 => todo!("PUTSP"), - 0x25 => todo!("HALT"), + 0x25 => vm.running = false, _ => unimplemented!(), } } diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 30e54f2..43594fd 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -138,6 +138,7 @@ impl Memory { pub struct VM { mem: Memory, registers: Registers, + running: bool, } impl VM { @@ -145,6 +146,7 @@ impl VM { VM { mem: Memory::new(), registers: Registers::new(), + running: false, } } @@ -187,9 +189,9 @@ impl VM { } pub fn execute(&mut self) { - let mut running: bool = true; + self.running = true; - while running { + while self.running { let instr = self.mem.get_mem(self.registers.pc); // NOTE @@ -197,7 +199,7 @@ impl VM { // disallow reading past memory bounds if self.registers.pc as usize == MEM_SIZE - 1 { - running = false + self.running = false } else { self.registers.pc += 1; }