Browse Source

toyvm: print next instruction during execution

pull/7/head
Murad Karammaev 2 years ago
parent
commit
4035bdb114
Signed by: foxpy GPG Key ID: 78BE32418B0C8450
  1. 4
      toy_cpu_4bit/src/cpu.rs
  2. 2
      toyvm/src/main.rs

4
toy_cpu_4bit/src/cpu.rs

@ -36,6 +36,10 @@ impl Cpu {
}
}
pub fn next_instruction(&self) -> String {
format!("{:?}", decode(self.code[self.IP.0 as usize]))
}
fn load(&mut self, reg: Register, addr: u4) {
match reg {
Register::R0 => self.R0 = Wrapping(self.data[u8::from(addr) as usize]),

2
toyvm/src/main.rs

@ -35,6 +35,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let code = read_code(args.code)?;
let mut cpu = Cpu::new(&code);
loop {
println!("{}", cpu.next_instruction());
if cpu.step() {
break;
}
@ -42,5 +43,6 @@ fn main() -> Result<(), Box<dyn Error>> {
cpu.visualize();
}
}
cpu.visualize();
Ok(())
}

Loading…
Cancel
Save