From ced4757324d0eac5a26f14da7de4abc875019af1 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Tue, 24 Dec 2024 17:42:11 -0700 Subject: Fix stack local access --- src/interpreter.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 9f226ae..686a3ff 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -280,9 +280,9 @@ impl Interpreter { Operand::Constant(value) => *value as u32, Operand::PopStack => self.pop_stack(), Operand::FrameIndirect(offset) => { - let start_of_locals = self.get_word(self.reg_frame, ReadWriteDest::Stack); - assert!(start_of_locals + offset < self.reg_stack, "Frame offset out of frame"); - self.get_word(start_of_locals + offset, ReadWriteDest::Stack) + let locals_pos = self.get_word(self.reg_frame + 4, ReadWriteDest::Stack); + assert!(self.reg_frame + locals_pos + offset < self.reg_stack, "Frame offset out of frame"); + self.get_word(self.reg_frame + locals_pos + offset, ReadWriteDest::Stack) }, Operand::MemIndirect(address) => { // TODO: Handle heap @@ -304,9 +304,9 @@ impl Interpreter { Operand::Constant(constant_dst) => panic!("Cannot store to constant operand {constant_dst}"), Operand::PopStack => self.push_stack(value), Operand::FrameIndirect(offset) => { - let start_of_locals = self.get_word(self.reg_frame, ReadWriteDest::Stack); - assert!(start_of_locals + offset < self.reg_stack, "Frame offset out of frame"); - self.write_word(start_of_locals + offset, ReadWriteDest::Stack, value) + let locals_pos = self.get_word(self.reg_frame + 4, ReadWriteDest::Stack); + assert!(self.reg_frame + locals_pos + offset < self.reg_stack, "Frame offset out of frame"); + self.write_word(self.reg_frame + locals_pos + offset, ReadWriteDest::Stack, value) }, Operand::MemIndirect(address) => { assert!(*address >= self.mem_writeable, "Cannot write to ROM"); -- cgit 1.4.1