Skip to content

Commit aaa36ec

Browse files
Samuel OrtizSamuel Ortiz
Samuel Ortiz
authored and
Samuel Ortiz
committed
do-core1: do-core: Add opcode and operand getters
Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 89e27af commit aaa36ec

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

do-core/src/instruction.rs

+12
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ impl Instruction {
5050

5151
Ok(Instruction { opcode, op0, op1 })
5252
}
53+
54+
pub fn opcode(&self) -> OpCode {
55+
self.opcode.clone()
56+
}
57+
58+
pub fn op0(&self) -> u8 {
59+
self.op0
60+
}
61+
62+
pub fn op1(&self) -> u8 {
63+
self.op1
64+
}
5365
}

src/main.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ fn main() -> Result<(), Error> {
4343
"do-core-1: instruction decoded into {:?}",
4444
decoded_instruction
4545
);
46-
let op0 = decoded_instruction.op0 as usize;
47-
let op1 = decoded_instruction.op1 as usize;
46+
let op0 = decoded_instruction.op0() as usize;
47+
let op1 = decoded_instruction.op1() as usize;
4848

49-
match decoded_instruction.opcode {
49+
match decoded_instruction.opcode() {
5050
OpCode::ADD => registers[op0] = add(registers[op0], registers[op1])?,
5151
OpCode::XOR => registers[op0] = xor(registers[op0], registers[op1]),
52-
53-
_ => panic!("Unknown opcode {:?}", decoded_instruction.opcode),
52+
_ => panic!("Unknown opcode {:?}", decoded_instruction.opcode()),
5453
}
5554

5655
dump_cpu_state("Final CPU state", &registers);

0 commit comments

Comments
 (0)