From 5af3a7e7382ceae6f8437b08576655db371566df Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 8 Feb 2023 14:46:56 +0100 Subject: [PATCH] Remove instructions in favor of memory --- src/simulator/machine.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 44888f4..887a297 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -58,9 +58,9 @@ impl Register { pub struct Machine { pub pc : u64, + pub sp: usize, pub int_reg : Register, pub fp_reg : Register, - pub instructions : [u64 ; 100], pub main_memory : [u8 ; MEM_SIZE], pub shiftmask : [u64 ; 64] // futur taille à calculer int memSize = g_cfg->NumPhysPages * g_cfg->PageSize; @@ -80,12 +80,9 @@ impl Machine { value >>= 1; } - // let int_reg = Register::::init(); - // let fp_reg = Register::::init(); - Machine { pc : 0, - instructions : [0 ; 100], + sp: 0, int_reg : Register::::init(), fp_reg : Register::::init(), main_memory : [0 ; MEM_SIZE], @@ -167,12 +164,17 @@ impl Machine { float localFloat; uint64_t value;*/ - if machine.instructions.len() <= machine.pc as usize { + if machine.main_memory.len() <= machine.pc as usize { println!("ERROR : number max of instructions rushed"); return ; } + let mut val: [u8; 8] = [0; 8]; + for i in 0..8 { + val[i] = machine.main_memory[machine.pc as usize + i]; + } - let inst : Instruction = decode(machine.instructions[machine.pc as usize]); + let val = u64::from_le_bytes(val); + let inst : Instruction = decode(val); match inst.opcode { @@ -588,7 +590,7 @@ impl Machine { _ => { panic!("{} opcode non géré", inst.opcode)}, } - machine.pc += 4; + machine.pc += 8; } }