Code Monkey home page Code Monkey logo

cm_vm's Introduction

cm_vm

Overview

Virtual machine for the purpose of primitive studies

  1. Can run commands program, ex. Repl.run_program(program). Each command converts to bytes command Assembler::parse_instruction() -> AssemblerInstruction

Program example:

",registers",
",program",
"load $1 #1000",   // LOAD $#1 #((0000.0011 << 8) + 1110.1000 = 1000)
"load $0 #999",
"add $0 $1 $2",
"sub $1 $0 $1",
"load $3 #4",
"jmpf $3", 
"sub $2 $0 $2",
"load $4 #4",
"eq $3 $4 $4",
",equal_flag",
".uselessdirective $0 $1 #100",
",registers",
",program",

  1. Can run Assembler hex instuctions, ex. Repl.run_hex_program(hex_program)

Program example:

",registers",
",program",
"00 01 03 E8",   // LOAD $#1 #((0000.0011 << 8) + 1110.1000 = 1000)
",registers",
",commands",
",program",

Supported directives:

,program - Listing instructions currently in VM's program vector
,registers - Listing registers and all contents:
,equal_flag - VM equel flag state (true/false)
,quit - Quit 

Supported tokens:

Op { code: Opcode },
Register { reg_num: u8 },
Number { value: i32 },
Directive { name: String },

Supported instuctions:

LOAD, // `LOAD $0 #500` Load value into register $0. #500 16 bits
ADD,  // `ADD $0 $1 $2` add $0 + $1 registers. Save to $2 register
SUB,  // `SUB $0 $1 $2` sub $0 - $1 registers. Save to $2 register
MUL,  // `MUL $0 $1 $2` mul $0 * $1 registers. Save to $2 register
DIV,  // `DIV $0 $1 $2` mul $0 / $1 registers. Save to $2 register. Use `remainder`
HLT,  // Stop execution
JMP,  // `JMP $0`.  Jump to $0 program byte.  Absolute jump 
JMPF, // `JMPF $0`  Jump forwards by $0.      Relative jump
JMPB, // `JMPB $0`  Jump backwards by $0.     Relative jump  
EQ,   // `EQ  $0 $1 $unused`  aka ($0 == $1) Save result to `equal_flag`. Equal
NEQ,  // `NEQ $0 $1 $unused`  aka ($0 != $1) Save result to `equal_flag`. Not equal
GT,   // `GT  $0 $1 $unused`  aka ($0 >  $1) Save result to `equal_flag`. Greater than
LT,   // `LT  $0 $1 $unused`  aka ($0 <  $1) Save result to `equal_flag`. Less than
GTQ,  // `GTQ $0 $1 $unused`  aka ($0 >= $1) Save result to `equal_flag`. Greater than OR equal to
JEQ,  // `JEQ $0` Jump to $0 if equal (`equal_flag` is true)  Absolute jump 
ALOC, // `ALOC $0` Allocate $0 bytes of memory in the heap
IGL,  // Illegal

cm_vm's People

Contributors

cheshulko avatar

Watchers

 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.