impl MixBit {
// Clamps a u8 to a u6
+ // 0b0011_1111 = 64
fn value(&self) -> u8 {
- return self.v % 64;
+ return self.v & 0b0011_1111;
}
fn as_value(&self) -> MixBit {
MixBit { v: self.value() }
}
}
+
+// Useful function for "packed" bits like those used for opcodes
+fn address(high: MixBit, low: MixBit) -> u16 {
+ return ((high.value() as u16) << 6) | low.value() as u16;
+}
+
// > Each byte contains an unspecified amount of information but it must be capable of holding at
// > least 64 distinct values.
// > A computer word consists of five bytes and a sign. The sign portion has only two possible
rJ: Word,
}
-// hacing three values: LESS, EQUAL, or GREATER
+// having three values: LESS, EQUAL, or GREATER
#[derive(Debug, Default)]
enum ComparisonIndicator {
Less,
}
fn main() {
- println!(
- "{:?}",
- Word {
- sign: true,
- bytes: [MixBit { v: 255 }; 5]
- }
- .field_specification(0, 2)
- );
+ let fs = (Word {
+ sign: true,
+ bytes: [MixBit { v: 255 }; 5],
+ })
+ .field_specification(0, 2);
+ println!("{:?}", address(fs.bytes[0], fs.bytes[1]));
}