From 5fe10c1c344c5a50719a66e71520933607de563f Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Mon, 15 Jan 2024 11:21:22 -0600 Subject: [PATCH 1/1] Initial commit with types representing machine description --- .gitignore | 1 + Cargo.lock | 7 +++++ Cargo.toml | 8 ++++++ src/main.rs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9d1ca1d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "mix" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0acd9e5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mix" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..12a5f53 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,73 @@ +// > 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 +// values, + and -. +// u8 is the smallest standard primitive, no bounds checking for now. +#[derive(Debug, Default, Copy, Clone)] +struct Word { + sign: bool, + bytes: [u8; 5], +} + +impl Word { + fn new(sign: bool, bytes: [u8; 5]) -> Word { + Word { sign, bytes } + } +} + +// There are nine registers in MIX. +// We shall use a small letter "r", prefixed to the neame, to identify a MIX register. +#[derive(Debug, Default)] +struct Registers { + // Accumulator + rA: Word, + // Extension + rX: Word, + // Index registers: Should only hold 2 bytes together with a sign. + rI1: Word, + rI2: Word, + rI3: Word, + rI4: Word, + rI5: Word, + rI6: Word, + // Jump: holds two bytes; it behaves as if its sign is always + + rJ: Word, +} + +// hacing three values: LESS, EQUAL, or GREATER +#[derive(Debug, Default)] +enum ComparisonIndicator { + Less, + #[default] + Equal, + Greater, +} + +#[derive(Debug)] +struct Machine { + registers: Registers, + // Besides its registers, MIX contains: + // an overflow toggle + overflow: bool, + // a comparison indicator + comp: ComparisonIndicator, + // memory: 4000 words of storage, each word with five bytes and a sign) + memory: [Word; 4000], + // and input-output devices + // TODO? +} + +impl Machine { + fn default() -> Machine { + Machine { + registers: Registers::default(), + overflow: false, + comp: ComparisonIndicator::Equal, + memory: [Word::default(); 4000], + } + } +} + +fn main() { + println!("{:?}", Machine::default()); +} -- 2.20.1