Skip to content

A toy compiler that produces Kappa code from Counter Machine instructions.

License

Notifications You must be signed in to change notification settings

althonos/kmachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

κmachine

A toy compiler that produces Kappa code from counter machine instructions.

Syntax

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:

Usage

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

Instructions

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

About

This program was developed by Martin Larralde as the final project for the Biochemical Programming course (2.19) of the MPRI.

About

A toy compiler that produces Kappa code from Counter Machine instructions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages