diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 22:19:11 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 22:19:11 +1300 |
commit | 77067f6e244a9cf4a6ef59df2e3d735b4f172c35 (patch) | |
tree | 74eb1a226da5b367f65e2f9012dc8d440e1ccce5 /src/devices/math.rs | |
download | bedrock-pc-77067f6e244a9cf4a6ef59df2e3d735b4f172c35.zip |
First commitv0.1.0
Diffstat (limited to 'src/devices/math.rs')
-rw-r--r-- | src/devices/math.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/devices/math.rs b/src/devices/math.rs new file mode 100644 index 0000000..6260529 --- /dev/null +++ b/src/devices/math.rs @@ -0,0 +1,35 @@ +pub struct MathDevice { + pub operand_1: u16, + pub operand_2: u16, + pub product_high: u16, + pub product_low: u16, + pub quotient: u16, + pub remainder: u16, +} + +impl MathDevice { + pub fn new() -> Self { + Self { + operand_1: 0x0000, + operand_2: 0x0000, + product_high: 0x0000, + product_low: 0x0000, + quotient: 0x0000, + remainder: 0x0000, + } + } + + pub fn multiply(&mut self) { + let (high, low) = self.operand_1.widening_mul(self.operand_2); + self.product_high = high; + self.product_low = low; + } + + pub fn divide(&mut self) { + self.quotient = self.operand_1.checked_div(self.operand_2).unwrap_or(0); + } + + pub fn modulo(&mut self) { + self.remainder = self.operand_1.checked_rem(self.operand_2).unwrap_or(0); + } +} |