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; mod simulator;
use simulator::machine::Machine; use simulator::machine::Machine;
use simulator::mem_cmp; use simulator::{mem_cmp, loader};
fn main() { fn main() {
let mut m = Machine::_init_machine();
let path = "test_file_section.txt".to_string(); let path = "test_file_section.txt".to_string();
let checker = mem_cmp::Mem_Checker::from(&path); let mut m = loader::load(&path, 4);
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m); Machine::print_memory(&mut m);
Machine::run(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); let res = u64::from_str_radix(&line.unwrap(), 16);
match res { match res {
Ok(value) => { 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!() _ => panic!()
} }

View File

@ -609,6 +609,17 @@ impl Machine {
machine.pc += 4; // Possible bug avec jump 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)] #[cfg(test)]

View File

@ -232,11 +232,11 @@ fn one_hex_to_dec(c: char) -> u8 {
'E' | 'e' => 14, 'E' | 'e' => 14,
'F' | 'f' => 15, 'F' | 'f' => 15,
_ => { _ => {
let ret : u8 = c.to_digit(10).unwrap() as u8; let ret : u8 = c.to_digit(10).unwrap() as u8;
return ret; return ret;
}, },
}
} }
}

View File

@ -217,7 +217,7 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64
RISCV_SYSTEM => { RISCV_SYSTEM => {
"ecall".to_string() "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
} }
} }