From 2d69813f8818ab0827f4ff2d84c645a8908da34d Mon Sep 17 00:00:00 2001 From: Alan Li Date: Wed, 10 Apr 2024 11:03:07 -0400 Subject: [PATCH] memory prints and LOAD32 bug fix --- basic/src/bin/valida.rs | 24 ++++++++++++++++++++++++ machine/src/program.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/basic/src/bin/valida.rs b/basic/src/bin/valida.rs index 87f2346..b8e770d 100644 --- a/basic/src/bin/valida.rs +++ b/basic/src/bin/valida.rs @@ -214,6 +214,24 @@ fn set_bp(args: ArgMatches, context: &mut Context) -> Result> { let message = format!("Breakpoint set at pc: {}", pc); Ok(Some(message)) } +fn show_memory(args: ArgMatches, context: &mut Context) -> Result> { + let addr = args + .get_one::("addr") + .unwrap() + .parse::() + .unwrap(); + + // show memory at address, by default show 20 cells + let mut memory = String::new(); + for i in 0..8 { + let read_addr = addr + i * 4; + let string_val = context.machine_.mem().examine(read_addr); + let memory_str = format!("0x{:<8x} : {}\n", read_addr, string_val); + memory += &memory_str; + } + + Ok(Some(memory)) +} fn run_until(_: ArgMatches, context: &mut Context) -> Result> { let mut message = String::new(); @@ -282,6 +300,12 @@ fn repl_run(args: &Args) { .arg(Arg::new("size").required(false)), list_instrs, ) + .with_command( + Command::new("m") + .arg(Arg::new("addr").required(true)) + .about("show memory at address"), + show_memory, + ) .with_command( Command::new("reset").about("reset machine state!"), init_context, diff --git a/machine/src/program.rs b/machine/src/program.rs index 1ea765d..f61bcba 100644 --- a/machine/src/program.rs +++ b/machine/src/program.rs @@ -100,7 +100,7 @@ impl InstructionWord { ), valida_opcodes::STOP => "".to_string(), valida_opcodes::LOAD32 => { - format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[1]) + format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[2]) } valida_opcodes::STORE32 => { format!("{}(fp), {}(fp)", self.operands.0[1], self.operands.0[2])