A toy compiler that produces Kappa code from counter machine instructions.
The syntax is heavily inspired by the AT&T syntax of the GNU Assembler. The following example
program copies the content of register %rax
to register %rbx
using a temporary register %rcx
:
; clear content of %rcx
clr %rcx
cpy1: ; move %rax to both %rbx and %rcx
inc %rcx
inc %rbx
dec %rax
jz %rax, cpy2
jmp cpy1
cpy2: ; move %rcx back into %rax
inc %rax
dec %rcx
jz %rcx, cpy3
jmp cpy2
cpy3:
Provide the compiler with a pseudo-assembly program, and it will generate a self-sufficient Kappa source:
$ cargo run -- examples/loop.S
This program can then be run with KaSim
through the command line:
$ KaSim examples/loop.ka
Or you can open it with the KUI
to inspect the generated agents and rules:
Instruction | Supported | Emulated | Example |
---|---|---|---|
add |
✓ | add %rax, %rbx |
|
add * |
✓ | add $0x12, %rbx |
|
clr |
✓ | clr %rax |
|
cpy |
✓ | cpy %rax, %rbx |
|
inc |
✓ | inc %rcx |
|
jmp |
✓ | jmp label |
|
jnz |
✓ | jnz %rax, label |
|
jz |
✓ | jz %rax, label |
|
mov |
✓ | mov %rax, %rbx |
|
mov * |
✓ | mov $5, %rax |
|
mul |
✓ | mul %rax, %rbx |
|
swp |
✓ | swp %rax, %rbx |
This program was developed by Martin Larralde as the final project for the Biochemical Programming course (2.19) of the MPRI.