-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tomBoddaert/dev
2.0
- Loading branch information
Showing
44 changed files
with
3,886 additions
and
1,693 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
name = "lminc" | ||
version = "1.1.4" | ||
version = "2.0.0" | ||
authors = ["Tom Boddaert <[email protected]>"] | ||
edition = "2021" | ||
description = "An assembler and interpreter for the Little Minion Computer model created by Professor Magnus Bordewich of Durham University, based on the Little Man Computer created by Dr. Stuart Madnick of M.I.T. in 1965" | ||
readme = "README.md" | ||
homepage = "https://github.com/tomBoddaert/lminc/" | ||
repository = "https://github.com/tomBoddaert/lminc/" | ||
license = "Creative Commons Attribution 4.0 International" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["assembler", "utility", "binary", "compiler"] | ||
categories = ["simulation", "compilers"] | ||
|
||
|
@@ -18,6 +18,19 @@ doc = true | |
edition = "2021" | ||
crate-type = ["lib"] | ||
|
||
[features] | ||
default = ["std", "extended"] | ||
alloc = [] | ||
std = ["alloc"] | ||
extended = [] | ||
|
||
[[bin]] | ||
name = "lminc" | ||
path = "src/main.rs" | ||
doc = false | ||
edition = "2021" | ||
required-features = ["std"] | ||
|
||
[profile.dev] | ||
opt-level = 0 | ||
debug = 2 | ||
|
@@ -33,10 +46,6 @@ lto = "fat" | |
panic = "abort" | ||
codegen-units = 1 | ||
|
||
[dependencies] | ||
lazy_static = "1.4.0" | ||
regex = "1.6.0" | ||
|
||
# UUID used in tests in src/loader.rs | ||
[dev-dependencies.uuid] | ||
version = "1.2.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
[![Rust](https://github.com/tomBoddaert/lminc/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/tomBoddaert/lminc/actions/workflows/rust.yml) | ||
[![rust-clippy analyze](https://github.com/tomBoddaert/lminc/actions/workflows/rust-clippy.yml/badge.svg?event=push)](https://github.com/tomBoddaert/lminc/actions/workflows/rust-clippy.yml) | ||
|
||
# LMinC | ||
|
||
|
@@ -15,16 +14,11 @@ Make sure you have [cargo](https://rustup.rs/) installed. | |
cargo install --git https://github.com/tomboddaert/lminc | ||
``` | ||
|
||
## Building from source | ||
- Use `cargo build --release` to compile the binary | ||
- Use `./target/release/lminc help` for instructions | ||
- If you want to install it, copy the binary (lminc) out of target/release/ to wherever you store your binaries (/usr/local/bin/ is recommended on Linux) | ||
|
||
## Examples | ||
|
||
### Assembly examples | ||
- There is an example of assembly in [examples/fib.txt](examples/fib.txt). | ||
- There are an exmaple of number assembly in [examples/fib_num.txt](examples/fib_num.txt). | ||
- There are an example of number assembly in [examples/fib_num.txt](examples/fib_num.txt). | ||
|
||
### Library examples | ||
- There is an example of assembling and running from assembly in [examples/fibonacci.rs](examples/fibonacci.rs) | ||
|
@@ -35,7 +29,4 @@ cargo install --git https://github.com/tomboddaert/lminc | |
I am working on an extended mode. The documentation is in [extended_mode.md](extended_mode.md). | ||
|
||
## License | ||
[LMinC](https://github.com/tomBoddaert/lminc) © 2022 by [Tom Boddaert](https://tomboddaert.com/) is licensed under [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/) | ||
|
||
## Contact | ||
Email me at [[email protected]](mailto:[email protected]), or contact me by a different method at [tomBoddaert.com/contact](https://tomboddaert.com/contact) | ||
[LMinC](https://github.com/tomBoddaert/lminc) is dual-licensed under either the [Apache License Version 2.0](/server/LICENSE_APACHE) OR [MIT](/server/LICENSE_MIT) license at your option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LDA one # load 1 and store it at address 98 | ||
STO 98 | ||
ADD one # add 1 and store it at address 99 | ||
STO 99 | ||
LDA 98 # load address 98 and output (1) | ||
OUT | ||
LDA 99 # load address 99 and output (2) | ||
OUT | ||
HLT # stop | ||
|
||
# constants | ||
one DAT 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[cfg(all(feature = "std", feature = "extended"))] | ||
mod example { | ||
use lminc::{assembler, runner::stdio::Runner}; | ||
|
||
/// Imported assembly | ||
const ASSEMBLY: &str = include_str!("extended_input.txt"); | ||
|
||
pub fn main() { | ||
// Assemble the assembly | ||
let memory = assembler::assemble_from_text(ASSEMBLY) | ||
.expect("failed to parse") | ||
.expect("failed to assemble"); | ||
|
||
// Create the runner, which also initialises the computer | ||
let mut runner = Runner::new(memory); | ||
|
||
// Run the computer | ||
if let Err(error) = runner.run() { | ||
eprintln!("{error}"); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(not(all(feature = "std", feature = "extended")))] | ||
mod example { | ||
pub fn main() { | ||
eprintln!("To run this example, the `std` and `extended` features must be enabled!"); | ||
} | ||
} | ||
|
||
/// Takes an input character and a number and repeats the character that many times | ||
fn main() { | ||
example::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
DAT 010 # Set extended mode | ||
EXT # enable extended mode | ||
|
||
INA # Take input character | ||
STO c # Store it | ||
IN # Take an input number | ||
loop STO n # Store it | ||
LDA c # Load the character | ||
OTA # Output the character | ||
LDA n # Load the counter | ||
SUB one # Subtract one | ||
BRZ end # If the counter is zero, stop | ||
BR loop # Otherwise, loop | ||
INA # take and store the character input | ||
STO c | ||
IN # take the number input | ||
loop BRZ exit # if zero, go to the exit | ||
STO n # store whats in the register | ||
LDA c # load and output the character | ||
OTA | ||
LDA n # load the counter | ||
SUB one # subtract one | ||
BR loop # otherwise, go to the start of the loop | ||
|
||
end LDA nl # Load nl | ||
OTA # Output nl | ||
HLT # Stop | ||
exit LDA nl # load and output nl | ||
OTA | ||
HLT # stop | ||
|
||
one DAT 001 # Data: one = 1 | ||
nl DAT 010 # Data: nl = '\n' | ||
# state | ||
c DAT 000 # the inputted character | ||
n DAT 000 # the inputted number | ||
|
||
# constants | ||
one DAT 1 | ||
nl DAT 010 # the new line character ('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[cfg(all(feature = "std", feature = "extended"))] | ||
mod example { | ||
use lminc::{assembler, runner::stdio::Runner}; | ||
|
||
/// Imported assembly | ||
const ASSEMBLY: &str = include_str!("extended_output.txt"); | ||
|
||
pub fn main() { | ||
// Assemble the assembly | ||
let memory = assembler::assemble_from_text(ASSEMBLY) | ||
.expect("failed to parse") | ||
.expect("failed to assemble"); | ||
|
||
// Create the runner, which also initialises the computer | ||
let mut runner = Runner::new(memory); | ||
|
||
// Run the computer | ||
if let Err(error) = runner.run() { | ||
eprintln!("{error}"); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(not(all(feature = "std", feature = "extended")))] | ||
mod example { | ||
pub fn main() { | ||
eprintln!("To run this example, the `std` and `extended` features must be enabled!"); | ||
} | ||
} | ||
|
||
/// Prints a message | ||
fn main() { | ||
example::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
DAT 010 # Set extended mode | ||
EXT # enable extended mode | ||
|
||
loop LDA first # Load the current character (modified) | ||
BRZ end # If null, stop | ||
OTA # Output the character | ||
LDA loop # Load the character loading instruction | ||
ADD one # Add one to the address (not safe) | ||
STO loop # Store the modified instruction | ||
BR loop # Loop | ||
loop LDA first # (modified) load the current character | ||
BRZ exit # if null, stop | ||
OTA # output the character | ||
LDA loop # load the character loading instruction | ||
ADD one # add one to the address | ||
STO loop # store the modified instruction | ||
BR loop # go to the start of the loop | ||
|
||
end HLT # Stop | ||
exit HLT # stop | ||
|
||
one DAT 001 # Data: one = 1 | ||
# constants | ||
one DAT 1 | ||
|
||
first DAT 072 # A string of characters | ||
DAT 101 | ||
DAT 108 | ||
DAT 108 | ||
DAT 111 | ||
DAT 032 | ||
DAT 119 | ||
DAT 111 | ||
DAT 114 | ||
DAT 108 | ||
DAT 100 | ||
DAT 033 | ||
DAT 010 # Terminated by a newline | ||
HLT # and a null | ||
# data | ||
first DAT 072 # a string of characters | ||
DAT 101 | ||
DAT 108 | ||
DAT 108 | ||
DAT 111 | ||
DAT 032 | ||
DAT 119 | ||
DAT 111 | ||
DAT 114 | ||
DAT 108 | ||
DAT 100 | ||
DAT 033 | ||
DAT 010 # ending in a newline | ||
DAT 000 # and terminated with a null (zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
start LDA a # Load a | ||
ADD b # Add b | ||
OUT # Output a + b | ||
STO c # Store a + b in c | ||
LDA b # Load b | ||
STO a # Store b in a | ||
LDA c # Load c | ||
STO b # Store c in b | ||
LDA max # Load max | ||
SUB c # Subtract max from c | ||
BRP start # If max > c, jump to start | ||
end HLT # Stop | ||
a DAT 0 # Data: a (lower value) | ||
b DAT 1 # Data: b (upper value) | ||
max DAT 100 # Data: max (max value) | ||
start LDA a # load a and add b | ||
ADD b | ||
OUT # output and store in c | ||
STO c | ||
LDA b # load b and store in a | ||
STO a | ||
LDA c # load c and store in b | ||
STO b | ||
LDA max # load max | ||
SUB c # subtract c from max | ||
BRP start # if max > c, jump to start | ||
end HLT # stop | ||
|
||
# state | ||
a DAT 0 # lower value | ||
b DAT 1 # upper value | ||
c DAT 0 # temporary | ||
|
||
# constants | ||
max DAT 100 # max value |
Oops, something went wrong.