Giter Club home page Giter Club logo

stack-vm's Introduction

Stack virtual mashine

Stack virtual mashine, that supports simple stacking operations, implemented in Rebol 2.

Running

For run vm, just clone repo. Rebol 2 must be installed and available in your OS.

git clone [email protected]:KirillTemnov/stack-vm.git
cd stack-vm

Using

For execute code in virtual mashine, you can write code in assembler, or use one of examples.

For launching assembler code, firstly, you must tanslate it to a mashine code by passing filename to translator:

./translator.r samples/sum.asm

If no errors found, translator will put mashine code to console (like #{000002007B02021F039899} for sum.asm example).

Then, you may load this code into vm, by launching Rebol in root project folder and apply these instructions:

do %vm.r
vm: make vitrual-mashine []
vm/run #{000002007B02021F039899}

You can inspect all vm variables after executiong a code. For more verbosity during run code process, set debug flag:

vm: make vitrual-mashine [debug: true]

Data types

For now, vm use only integer values, that fit in one word (#{FFFF}). Negative values partially supported.

Quick guide on assembler

Each assembly file must contain .code section. Program execution started from first instruction after begining of .code section.

If you plan to store/load variables, provide .data section, before .code. Each line of data section consist of label sw and decimal value. E.g.:

.data
  myVar         sw      10
  mySecondVar   sw      1024

Labels and function names consist of english alphanumeric chars and _. Must be started from any letter.

Empty lines and comments ignored by translator. Comments strated from ; and passed till the end of line.

Assembler commands

name explain
nop No operation.
push Push variable to data-stack.
add Eval sum of first and second values in data-stack, remove them from data-stack and put result on top of it
sub Substract second value from first in data-stack, remove both variables from data-stack and put result on top of it
and Apply and operation on first and second values in data-stack, remove both from data-stack and put result on top of it
or Execute or operation. Works same as and
xor Execute exclusive or operation. Works same as and
inc Increment first value in data-stack
dec Deccrement first value in data-stack
drop Extrat first value from data-stack.
dup Copy first value in data-stack and put it on top of data-stack
over Copy second value in data-stack and put it on top of data-stack
load Load variable (by name) from memory section on top of data-stack
stor Store first value in data-stack into variable in memory
call Call subroutine by name
retn Return from subroutine
jmp Unconditional jump to label
jz Jump to label if zero flag is set (registers/zf = 1)
jnz Jump to label if zero flag is not set (registers/zf = 0)
stat Show vm status on console. Shows data-stack, memory and registers
halt Halt mashine - end of a program

Testing

./run-tests

Don't tried to run tests on windows, please report on fails, if any.

License

Released under the MIT license.

stack-vm's People

Contributors

kirilltemnov avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.