diff --git a/src/machine.rs b/src/machine.rs index 1ac9c62..bc53171 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); }