implement HALT trap routine

This commit is contained in:
dogeystamp 2024-01-06 13:50:36 -05:00
parent 6fe7dffb4d
commit 928afa6de8
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 6 additions and 4 deletions

View File

@ -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!(),
}
}

View File

@ -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;
}