Skip to content

Latest commit

 

History

History
120 lines (109 loc) · 2.84 KB

b4i-tests.org

File metadata and controls

120 lines (109 loc) · 2.84 KB

b4i macro and interactive commands test suite

About this file

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.

Macros

.i .e .t (if/else/then)

> :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

.w .d .z (while/do)

> :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

.f .n (for/next)

> :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

.^ (linked list)

> :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).

Interactive Commands

%R (reset)

> 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.

%C (clear)

> 01 02 03 ?d %R ?d %q
ds: [1 2 3]
ds: []
= %C : clear the virtual machine
: clears the stacks and resets memory

$label (use label)

> :foo
> $foo ?d %q
ds: [100]
= $label : use label
: pushes the address of the label onto the stack

?m (show memory)

> :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

TODO: Additional tests for other macros and interactive commands

%e (run to end)

##+name: interactive.run-to-end ##+begin_src b4a = %e : run to end

executes instructions until a return is encountered

##+end_src

%\ (goto)

##+name: interactive.goto ##+begin_src b4a = %\ : goto

jumps to the address stored in the "@\" register

##+end_src