Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lialan committed Apr 10, 2024
1 parent a9aa501 commit cb8d47d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 11 additions & 6 deletions basic/src/bin/valida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ impl Context<'_> {
let pc = self.machine_.cpu().pc;
let fp = self.machine_.cpu().fp;

let instruction = self.machine_.program().program_rom.get_instruction(pc);
println!("{:4} : {:?}", pc, instruction.to_string());

// check if fp is changed
if fp != self.recorded_current_fp_ {
self.last_fp_size_ = self.recorded_current_fp_ - fp;
Expand Down Expand Up @@ -182,11 +185,13 @@ fn list_instrs(args: ArgMatches, context: &mut Context) -> Result<Option<String>
let program_rom = &context.machine_.program().program_rom;
let total_size = program_rom.0.len();

let print_size = args
.get_one::<String>("size")
.unwrap()
.parse::<u32>()
.unwrap();
let print_size_arg = args
.get_one::<String>("size");

let print_size = match print_size_arg {
Some(size) => size.parse::<u32>().unwrap(),
None => 10,
};

let mut formatted = String::new();
for i in 0..print_size {
Expand All @@ -195,7 +200,7 @@ fn list_instrs(args: ArgMatches, context: &mut Context) -> Result<Option<String>
break;
}
let instruction = program_rom.get_instruction(cur_pc);
formatted.push_str(format!("{:?} : {:?}\n", cur_pc, instruction.to_string()).as_str());
formatted.push_str(format!("{:4} : {:?}\n", cur_pc, instruction.to_string()).as_str());
}
Ok(Some(formatted))
}
Expand Down
10 changes: 10 additions & 0 deletions machine/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ impl InstructionWord<i32> {
self.print_first_operand(),
self.print_second_operand()),
valida_opcodes::STOP => "".to_string(),
valida_opcodes::LOAD32 =>
format!(
"{}(fp), {}(fp)",
self.operands.0[0],
self.operands.0[1]),
valida_opcodes::STORE32 =>
format!(
"{}(fp), {}(fp)",
self.operands.0[1],
self.operands.0[2]),
_ => {
format!(
"{}(fp), {}, {}", self.operands.0[0], self.print_first_operand(), self.print_second_operand()
Expand Down

0 comments on commit cb8d47d

Please sign in to comment.