1
0

32 lines
817 B
Rust
Raw Normal View History

use crate::{Argument, Instruction, Operation};
2024-11-26 07:14:30 -05:00
pub struct Divide {
pub destination: u8,
2024-11-26 07:14:30 -05:00
pub left: Argument,
pub right: Argument,
}
impl From<&Instruction> for Divide {
fn from(instruction: &Instruction) -> Self {
let destination = instruction.a;
2024-11-26 07:14:30 -05:00
let (left, right) = instruction.b_and_c_as_arguments();
Divide {
destination,
2024-11-26 07:14:30 -05:00
left,
right,
}
}
}
impl From<Divide> for Instruction {
fn from(divide: Divide) -> Self {
let a = divide.destination;
2024-12-08 08:01:15 -05:00
let (b, b_options) = divide.left.as_index_and_b_options();
let (c, c_options) = divide.right.as_index_and_c_options();
let metadata = Operation::Divide as u8 | b_options.bits() | c_options.bits();
Instruction { metadata, a, b, c }
2024-11-26 07:14:30 -05:00
}
}