2024-12-09 07:01:07 -05:00
|
|
|
use crate::{Argument, Instruction, Operation};
|
2024-11-26 07:14:30 -05:00
|
|
|
|
|
|
|
pub struct Divide {
|
2024-12-09 07:01:07 -05:00
|
|
|
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 {
|
2024-12-11 06:49:43 -05:00
|
|
|
let destination = instruction.a_field();
|
2024-11-26 07:14:30 -05:00
|
|
|
let (left, right) = instruction.b_and_c_as_arguments();
|
|
|
|
|
|
|
|
Divide {
|
2024-11-28 01:10:49 -05:00
|
|
|
destination,
|
2024-11-26 07:14:30 -05:00
|
|
|
left,
|
|
|
|
right,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Divide> for Instruction {
|
|
|
|
fn from(divide: Divide) -> Self {
|
2024-12-11 09:26:38 -05:00
|
|
|
let operation = Operation::DIVIDE;
|
2024-12-09 07:01:07 -05:00
|
|
|
let a = divide.destination;
|
2024-12-11 06:49:43 -05:00
|
|
|
let (b, b_is_constant) = divide.left.as_index_and_constant_flag();
|
|
|
|
let (c, c_is_constant) = divide.right.as_index_and_constant_flag();
|
2024-11-28 01:10:49 -05:00
|
|
|
|
2024-12-11 06:49:43 -05:00
|
|
|
Instruction::new(operation, a, b, c, b_is_constant, c_is_constant, false)
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|