print_memory dans Machine

This commit is contained in:
Baptiste 2023-03-01 15:11:35 +01:00
parent f6ff30b63c
commit 73c49414ff
5 changed files with 19 additions and 10 deletions

View File

@ -1,13 +1,11 @@
mod simulator;
use simulator::machine::Machine;
use simulator::mem_cmp;
use simulator::{mem_cmp, loader};
fn main() {
let mut m = Machine::_init_machine();
let path = "test_file_section.txt".to_string();
let checker = mem_cmp::Mem_Checker::from(&path);
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m);
let mut m = loader::load(&path, 4);
Machine::print_memory(&mut m);
Machine::run(m);
mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
}

View File

@ -24,7 +24,7 @@ pub fn load(path : &str, instruction_size: i32) -> Machine {
let res = u64::from_str_radix(&line.unwrap(), 16);
match res {
Ok(value) => {
Machine::write_memory(&mut machine, instruction_size, i, value);
Machine::write_memory(&mut machine, instruction_size, i*instruction_size as usize, value);
},
_ => panic!()
}

View File

@ -609,6 +609,17 @@ impl Machine {
machine.pc += 4; // Possible bug avec jump
}
pub fn print_memory(machine : &mut Machine) {
for i in 0..MEM_SIZE {
if i%16 == 0 {
print!("\n@{:04x} ", i);
}
print!("{:02x}", machine.main_memory[i]);
}
println!();
}
}
#[cfg(test)]

View File

@ -236,7 +236,7 @@ fn one_hex_to_dec(c: char) -> u8 {
return ret;
},
}
}
}

View File

@ -217,7 +217,7 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64
RISCV_SYSTEM => {
"ecall".to_string()
},
_ => todo!("Unknown or currently unsupported opcode") // Change todo! to panic! in the future, I put todo! because there's a lot of opcode currently not implemented
_ => todo!("{:x} opcode non géré pc : {:x}, value : {:x}", ins.opcode, pc, ins.value) // Change todo! to panic! in the future, I put todo! because there's a lot of opcode currently not implemented
}
}