Skip to content

Commit

Permalink
memory prints and LOAD32 bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lialan committed Apr 10, 2024
1 parent bec888e commit 2d69813
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions basic/src/bin/valida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ fn set_bp(args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
let message = format!("Breakpoint set at pc: {}", pc);
Ok(Some(message))
}
fn show_memory(args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
let addr = args
.get_one::<String>("addr")
.unwrap()
.parse::<u32>()
.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<Option<String>> {
let mut message = String::new();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion machine/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl InstructionWord<i32> {
),
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])
Expand Down

0 comments on commit 2d69813

Please sign in to comment.