Skip to content

Commit

Permalink
do-core1: do-core: Add opcode and operand getters
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Ortiz <[email protected]>
  • Loading branch information
Samuel Ortiz authored and Samuel Ortiz committed Feb 26, 2022
1 parent 89e27af commit aaa36ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 12 additions & 0 deletions do-core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,16 @@ impl Instruction {

Ok(Instruction { opcode, op0, op1 })
}

pub fn opcode(&self) -> OpCode {
self.opcode.clone()
}

pub fn op0(&self) -> u8 {
self.op0
}

pub fn op1(&self) -> u8 {
self.op1
}
}
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ fn main() -> Result<(), Error> {
"do-core-1: instruction decoded into {:?}",
decoded_instruction
);
let op0 = decoded_instruction.op0 as usize;
let op1 = decoded_instruction.op1 as usize;
let op0 = decoded_instruction.op0() as usize;
let op1 = decoded_instruction.op1() as usize;

match decoded_instruction.opcode {
match decoded_instruction.opcode() {
OpCode::ADD => registers[op0] = add(registers[op0], registers[op1])?,
OpCode::XOR => registers[op0] = xor(registers[op0], registers[op1]),

_ => panic!("Unknown opcode {:?}", decoded_instruction.opcode),
_ => panic!("Unknown opcode {:?}", decoded_instruction.opcode()),
}

dump_cpu_state("Final CPU state", &registers);
Expand Down

0 comments on commit aaa36ec

Please sign in to comment.