simulate some instructions
This commit is contained in:
parent
c5291b7a3b
commit
240f029881
@ -1,5 +1,3 @@
|
|||||||
#[warn(unused_parens)]
|
|
||||||
|
|
||||||
use crate::decode::*;
|
use crate::decode::*;
|
||||||
use crate::print::*;
|
use crate::print::*;
|
||||||
|
|
||||||
@ -26,12 +24,40 @@ impl Machine {
|
|||||||
println!("ERROR : number max of instructions rushed");
|
println!("ERROR : number max of instructions rushed");
|
||||||
return machine;
|
return machine;
|
||||||
}
|
}
|
||||||
|
|
||||||
let inst : Instruction = decode(machine.instructions[machine.pc as usize]);
|
let inst : Instruction = decode(machine.instructions[machine.pc as usize]);
|
||||||
machine.pc += 1;
|
machine.pc += 1;
|
||||||
|
|
||||||
match (inst.opcode) {
|
match (inst.opcode) {
|
||||||
RISCV_LUI => {
|
RISCV_LUI => {
|
||||||
machine.int_reg[inst.rd as usize] = inst.imm31_12;
|
machine.int_reg[inst.rd as usize] = inst.imm31_12;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//******************************************************************************************
|
||||||
|
// Treatment for: OPI INSTRUCTIONS
|
||||||
|
RISCV_OPI => {
|
||||||
|
match (inst.funct3) {
|
||||||
|
RISCV_OPI_ADDI => {
|
||||||
|
machine.int_reg[inst.rd as usize] = machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as u32;
|
||||||
|
},
|
||||||
|
RISCV_OPI_SLTI => {
|
||||||
|
machine.int_reg[inst.rd as usize] =
|
||||||
|
if machine.int_reg[inst.rs1 as usize] < inst.imm12_I_signed as u32 { 1 } else { 0 };
|
||||||
|
},
|
||||||
|
RISCV_OPI_XORI => {
|
||||||
|
machine.int_reg[inst.rd as usize] = machine.int_reg[inst.rs1 as usize] ^ inst.imm12_I_signed as u32;
|
||||||
|
},
|
||||||
|
RISCV_OPI_ORI => {
|
||||||
|
machine.int_reg[inst.rd as usize] = machine.int_reg[inst.rs1 as usize] | inst.imm12_I_signed as u32;
|
||||||
|
},
|
||||||
|
RISCV_OPI_ANDI => {
|
||||||
|
machine.int_reg[inst.rd as usize] = machine.int_reg[inst.rs1 as usize] & inst.imm12_I_signed as u32;
|
||||||
|
},
|
||||||
|
RISCV_OPI_SLLI => {
|
||||||
|
machine.int_reg[inst.rd as usize] = machine.int_reg[inst.rs1 as usize] << inst.shamt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
mod decode;
|
mod decode;
|
||||||
mod print;
|
mod print;
|
||||||
mod machine;
|
mod machine;
|
||||||
|
use machine::Machine;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let instr = decode::decode(98);
|
let mut m = Machine::_init_machine();
|
||||||
println!("{}", print::print(instr, 0));
|
|
||||||
|
|
||||||
let mut m = machine::Machine::_init_machine();
|
|
||||||
m.instructions[0] = 0x37;
|
m.instructions[0] = 0x37;
|
||||||
machine::Machine::oneInstruction(m);
|
Machine::oneInstruction(m);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user