Fixed a few old bugs

- Fixed a where the VM excuted one loop regardless of instructions.
- Use the full 32 bits if an instruction is less.
This commit is contained in:
Anthony Foxclaw 2020-02-09 18:43:23 -05:00
parent b825931ce5
commit 13069b7ebd
2 changed files with 8 additions and 4 deletions

View file

@ -35,6 +35,10 @@ impl AssemblerInstruction {
} }
} }
while results.len() < 4 {
results.push(0);
}
results results
} }

View file

@ -74,7 +74,7 @@ impl VM {
/// various public functions. /// various public functions.
fn execute_instruction(&mut self) -> bool { fn execute_instruction(&mut self) -> bool {
if self.pc >= self.program.len() { if self.pc >= self.program.len() {
return false; return true;
} }
match self.decode_opcode() { match self.decode_opcode() {
Opcode::LOAD => { Opcode::LOAD => {
@ -84,11 +84,11 @@ impl VM {
} }
Opcode::HLT => { Opcode::HLT => {
println!("HLT encountered"); println!("HLT encountered");
return false; return true;
} }
Opcode::IGL => { Opcode::IGL => {
println!("Unrecognized opcode found! Terminating!"); println!("Unrecognized opcode found! Terminating!");
return false; return true;
} }
Opcode::ADD => { Opcode::ADD => {
let reg1 = self.registers[self.next_8_bits() as usize]; let reg1 = self.registers[self.next_8_bits() as usize];
@ -214,7 +214,7 @@ impl VM {
self.heap.resize(new_end as usize, 0); self.heap.resize(new_end as usize, 0);
} }
} }
true false
} }
} }