From a4bae8a458d382aa2881431f704fb6157a4f0492 Mon Sep 17 00:00:00 2001 From: Alan Li Date: Tue, 16 Apr 2024 21:13:25 -0400 Subject: [PATCH] Fix jalv offset -- negative values allowed --- basic/src/bin/valida.rs | 2 +- cpu/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/basic/src/bin/valida.rs b/basic/src/bin/valida.rs index 5e4eff8..71aa70e 100644 --- a/basic/src/bin/valida.rs +++ b/basic/src/bin/valida.rs @@ -147,7 +147,7 @@ fn show_frame(args: ArgMatches, context: &mut Context) -> Result> let offset = i * -4; let read_addr = (fp + offset) as u32; let string_val = context.machine_.mem().examine(read_addr); - let frameslot_addr = format!("{}(fp)", offset); + let frameslot_addr = format!("0x{:8} | {:3}(fp)", read_addr, offset); let frameslot = format!("{:>7}", frameslot_addr); let frame_str = format!("\n{} : {}", frameslot, string_val); frame += &frame_str; diff --git a/cpu/src/lib.rs b/cpu/src/lib.rs index cbbcd89..2273f2c 100644 --- a/cpu/src/lib.rs +++ b/cpu/src/lib.rs @@ -521,7 +521,8 @@ where .mem_mut() .read(clk, read_addr, true, pc, opcode, 2, "") .into(); - state.cpu_mut().fp += cell; + let offset: i32 = cell as i32; + state.cpu_mut().fp = (state.cpu().fp as i32 + offset) as u32; state.cpu_mut().push_op(Operation::Jalv, opcode, ops); } }