Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ cargo run --bin rusty_man_computer -- --ram demos/factorial.bin

At the moment, the easiest way to write a program is using the assembly language in the [online simulator](https://peterhigginson.co.uk/lmc/). Write the assembly code, click "ASSEMBLE INTO RAM", and click-and-drag to copy the contents of the memory text boxes (you can leave out any empty memory at the end).

At the moment, you have to use a text editor to ensure that each memory cell is only separated by a space, and not a line break. (This can also be accomplished by pasting the memory contents into the address bar of your browser, and copying it from there.)

Then you can run `bin_creator`, giving it the file name that the binary file should be written to, e.g.

```bash
cargo run --bin bin_creator -- my_program.bin
```

Follow the prompt to paste the memory data into your terminal, and press Enter twice in a row to mark the end of the data.

Then you can run the program as described above, e.g.

```bash
Expand Down
11 changes: 9 additions & 2 deletions src/bin_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ fn main() -> Result<(), Box<dyn Error>> {
let filename = &args[1];

// Let the user paste in a string
println!("Paste in the memory data:");
println!("Paste the memory data below, then press Enter twice to submit:");
let mut line = String::new();
let stdin = io::stdin();
stdin.lock().read_line(&mut line)?;
// Accept input until enter is pressed twice
loop {
stdin.lock().read_line(&mut line)?;
if line.chars().rev().take(2).collect::<String>() == "\n\n" {
break;
}
}

// Split the string into a vector i16 signed ints
let memory_data_items: Vec<i16> = line
Expand All @@ -34,5 +40,6 @@ fn main() -> Result<(), Box<dyn Error>> {
// Write the memory data to a binary file
fs::write(filename, memory_data_bytes)?;

println!("Successfully created binary file: {}", filename);
Ok(())
}