first instruction in oneInstruction()

This commit is contained in:
Baptiste 2022-11-09 16:47:26 +01:00
parent f9af5c138f
commit a341493526
2 changed files with 32 additions and 9 deletions

View File

@ -1,23 +1,42 @@
use crate::decode::*; #[warn(unused_parens)]
use crate::decode::*;
use crate::print::*;
pub struct Machine { pub struct Machine {
pub _pc : u32, pub pc : u32,
pub _int_reg : [u32 ; 32], pub int_reg : [u32 ; 32],
pub _instructions : [u32 ; 100] pub instructions : [u32 ; 100]
} }
impl Machine { impl Machine {
fn _init_machine() -> Machine { pub fn _init_machine() -> Machine {
Machine { Machine {
_pc : 0, pc : 0,
_instructions : [0 ; 100], instructions : [0 ; 100],
_int_reg : [0 ; 32] 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)] #[cfg(test)]

View File

@ -5,4 +5,8 @@ mod machine;
fn main() { fn main() {
let instr = decode::decode(98); let instr = decode::decode(98);
println!("{}", print::print(instr, 0)); println!("{}", print::print(instr, 0));
let mut m = machine::Machine::_init_machine();
m.instructions[0] = 0x37;
machine::Machine::oneInstruction(m);
} }