This file demonstrates the macro and interactive commands. Currently these interactive features are present only in the lil implementation (`mb4.deck`). The macros are also available in the pascal version’s assembler.
> :E lb 'e tm rt
> :T lb 01 .i lb 'T ^E .e lb 'F ^E .t rt
> ^T %q
T
= if/else/then macro
: if the top of the stack is non-zero, execute the first block
: otherwise, execute the second block
> :E lb 'e tm rt
> :T lb 'a !A lb 03 .w du .d lb 01 +A ^E lb 01 sb .z rt
> ^T %q
a
b
c
= while/do macro
: while the top of the stack is non-zero, execute the block
: decrement the top of the stack each iteration
> :E lb 'e tm rt
> :T lb 03 .f cd du dc lb 'a ad ^E .n rt
> ^T %q
d
c
b
= for/next macro
: execute the block a fixed number of times
: the counter is stored on the control stack
> :100 .^ .^ .^ .^
> ?100 %q
.. .. .. .. .. ^A .. .. ^D ^A .. .. ^H ^A .. ..
= .^ : linked list
: creates a linked list in little endian format
: each node points to the previous node's address.
: The first four bytes are the null value `0x00`,
: then `0x100` (`00 01 00 00` in little endian format).
: then `0x104` (`04 01 00 00` in little endian format).
: then `0x108` (`08 01 00 00` in little endian format).
> 01 02 03 ?d %R ?d %q
ds: [1 2 3]
ds: []
= %R : reset the virtual machine
: resets the stacks and sets ip to 100.
: does not clear memory.
> 01 02 03 ?d %R ?d %q
ds: [1 2 3]
ds: []
= %C : clear the virtual machine
: clears the stacks and resets memory
> :foo
> $foo ?d %q
ds: [100]
= $label : use label
: pushes the address of the label onto the stack
> :100 01 02 03 04 'h 'e 'l 'l 'o
> ?100 %q
^A ^B ^C ^D +H +E +L +L +O .. .. .. .. .. .. ..
= ?m : show memory
: displays the contents of memory starting at the specified address
##+name: interactive.run-to-end ##+begin_src b4a = %e : run to end
executes instructions until a return is encountered
##+end_src
##+name: interactive.goto ##+begin_src b4a = %\ : goto
jumps to the address stored in the "@\" register
##+end_src