-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonacci.rs
34 lines (28 loc) · 850 Bytes
/
fibonacci.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[cfg(feature = "std")]
mod example {
use lminc::{assembler, runner::stdio::Runner};
/// Imported assembly
const ASSEMBLY: &str = include_str!("fib.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(feature = "std"))]
mod example {
pub fn main() {
eprintln!("To run this example, the `std` feature must be enabled!");
}
}
/// Runs the Fibonacci sequence and stops when it exceeds 100
fn main() {
example::main();
}