From a341493526ff9d4a23b82e46d5c0e2e23ad5c98f Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 9 Nov 2022 16:47:26 +0100 Subject: [PATCH] first instruction in oneInstruction() --- src/machine.rs | 37 ++++++++++++++++++++++++++++--------- src/main.rs | 4 ++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index 5845ae3..7cf6fe8 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,23 +1,42 @@ -use crate::decode::*; +#[warn(unused_parens)] +use crate::decode::*; +use crate::print::*; pub struct Machine { - pub _pc : u32, - pub _int_reg : [u32 ; 32], - pub _instructions : [u32 ; 100] + pub pc : u32, + pub int_reg : [u32 ; 32], + pub instructions : [u32 ; 100] } impl Machine { - - fn _init_machine() -> Machine { + + pub fn _init_machine() -> Machine { Machine { - _pc : 0, - _instructions : [0 ; 100], - _int_reg : [0 ; 32] + pc : 0, + instructions : [0 ; 100], + int_reg : [0 ; 32] } } + + pub fn oneInstruction(mut machine : Machine) -> Machine { + if (machine.instructions.len() <= machine.pc as usize) { + println!("ERROR : number max of instructions rushed"); + return machine; + } + let inst : Instruction = decode(machine.instructions[machine.pc as usize]); + machine.pc += 1; + match (inst.opcode) { + RISCV_LUI => { + machine.int_reg[inst.rd as usize] = inst.imm31_12; + }, + } + + + machine + } } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index 346a5b8..9eb5d76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,4 +5,8 @@ mod machine; fn main() { let instr = decode::decode(98); println!("{}", print::print(instr, 0)); + + let mut m = machine::Machine::_init_machine(); + m.instructions[0] = 0x37; + machine::Machine::oneInstruction(m); }