memory.txt can be execute
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
use std::{ops::{Add, Sub}, io::Write};
|
||||
|
||||
use crate::simulator::print;
|
||||
|
||||
use super::{decode::{Instruction, decode}};
|
||||
use super::global::*;
|
||||
use std::fs::File;
|
||||
@ -40,7 +42,7 @@ impl Register<i64> {
|
||||
self.register[position] = value;
|
||||
} else {
|
||||
// Panic ou rien ? (dans le doute pour le moment panic)
|
||||
unreachable!("You can't write to zero register")
|
||||
// unreachable!("You can't write to zero register")
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,6 +150,14 @@ impl Machine {
|
||||
file.write(&machine.main_memory);
|
||||
}
|
||||
|
||||
pub fn print_machine_status(machine: &mut Machine) {
|
||||
println!("######### Machine status #########");
|
||||
for i in 0..32 {
|
||||
println!(">{} : {:x}", print::REG_X[i], machine.int_reg.get_reg(i));
|
||||
}
|
||||
println!("##################################");
|
||||
}
|
||||
|
||||
/// Execute the instructions table of a machine putted in param
|
||||
///
|
||||
/// ### Parameters
|
||||
@ -182,13 +192,15 @@ impl Machine {
|
||||
if machine.main_memory.len() <= machine.pc as usize {
|
||||
panic!("ERROR : number max of instructions rushed");
|
||||
}
|
||||
let mut val: [u8; 8] = [0; 8];
|
||||
for i in 0..8 {
|
||||
let mut val: [u8; 4] = [0; 4];
|
||||
for i in 0..4 {
|
||||
val[i] = machine.main_memory[machine.pc as usize + i];
|
||||
}
|
||||
|
||||
let val = u64::from_be_bytes(val);
|
||||
println!("{:x}", val);
|
||||
let val = u32::from_be_bytes(val) as u64;
|
||||
Self::print_machine_status(machine);
|
||||
println!("executing instruction : {:016x} at pc {:x}", val, machine.pc);
|
||||
println!("{}", print::print(decode(val), machine.pc as i32));
|
||||
let inst : Instruction = decode(val);
|
||||
|
||||
|
||||
@ -602,7 +614,7 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)},
|
||||
_ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)},
|
||||
}
|
||||
|
||||
machine.pc += 4; // Possible bug avec jump
|
||||
|
Reference in New Issue
Block a user