1
0

32 lines
836 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,
}
2025-01-08 04:21:01 -05:00
impl From<Instruction> for Divide {
fn from(instruction: Instruction) -> Self {
let destination = instruction.a_field();
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 {
2024-12-11 09:26:38 -05:00
let operation = Operation::DIVIDE;
let a = divide.destination;
let (b, b_is_constant) = divide.left.as_index_and_constant_flag();
let (c, c_is_constant) = divide.right.as_index_and_constant_flag();
Instruction::new(operation, a, b, c, b_is_constant, c_is_constant, false)
2024-11-26 07:14:30 -05:00
}
}