helloworld/
helloworld.rs

1use esoteric_vm::{esoteric_assembly, Machine};
2
3fn main() -> Machine {
4    // initialize a new machine
5    let mut machine = Machine::default();
6
7    // assembly code for the machine
8    let asm = esoteric_assembly! {
9        // initialize dot pointer so that IO operations work
10
11        // push a dot character to stack
12        0: pushi b'.';
13        // pop to address 28657
14        2: pop 28657;
15
16        // set dot pointer to 28657 (has to be a prime or semiprime, which is also a fibonacci number)
17        5: ldidp 28657;
18
19        // -----------------
20
21        // print hello world
22        8: writeline 13;
23
24        // halt machine
25        11: Ωtheendisnear;
26        12: Ωskiptothechase;
27
28        // hello world text
29        13: data b"Hello, world!\n\0";
30    };
31
32    // load machine code
33    machine.load(&asm, 0);
34
35    // run machine until it halts
36    machine.run();
37
38    // return the machine's register A (unused)
39    machine
40}