Comp Mark II – Simple 4-bit virtual computer
MIT License
For quick start see HOW TO RUN
instruction code - 4 bits
| +-- address - 4 bits
v v
----***- -> READ 14 -> Copy value stored at address 14 of DATA ram to register.
JUMP
, IF MAX
, IF MIN
, ...). They refer to CODE part of ram.JRI~<>&V
) do not specify address. They operate on register (SHIFT L/R
, NOT
, ...) or between register and predefined DATA address (AND
, OR
, ...).*
is interpreted as true and all other characters as false. If word starts with a digit, it is then read as a number and converted appropriately.echo | ./comp <file>
s
key and loaded by passing their name as a parameter..cm2
will be loaded in an alphabetical order.Most of the instructions, together with the highlighted word that they use/modify, are pretty self-explainatory. Exception are instructions that start with -***
, and are a part of JRI~<>&VX
instruction cluster. They are:
J
– JUMP_REG,R
– READ_REG,I
– INIT,~
– NOT,<
– SHIFT_L,>
– SHIFT_R,&
– AND,V
– OR,X
– XOR.(Use Shift–Left/Right Arrow to easily shift between them.) Detailed descriptions of all instructions can be found HERE.
Space
– Flip bitTab
– Switch address spaceEnter
– Start/pause executionEsc
– Cancel executionDelete
, Backspace
– Delete word or move following words up if emptyInsert
, ]
– Insert empty word and move following words downs
– Save ram to textfile named punchcard-<num>.cm2
. To load it, start program with ./comp <file>
q
– Save and quitDetailed descriptions of all keys can be found HERE.
--non-interactive
, -n
– Runs program without an interface. Output is sent to stdout instead of a printer. This option is not necessary if any other option is present, or if input is piped in.--char-output
, -c
– Converts numbers to characters using ASCII standard when printing to stdout.--filter
, -f
– Convert characters to numbers when reading from stdin, and numbers to characters when printing to stdout.--game
, -g
– Same as filter, but reads characters directly from keyboard.parse
– Converts program to c++ code (other options may be specified).compile
– Compiles program to executable file, by converting it to c++ code and then running g++ compiler (other options from above may be specified). Only difference between compiled program and one run on the Comp Mark II is in execution speed.Make and g++ need to be installed first. On Ubuntu and Debian you can get them by running sudo apt-get install build-essential
, on OS X they get installed automatically after running make.
$ git clone https://github.com/gto76/comp-m2.git
$ cd comp-m2
$ ./run
$ docker run -it --rm mvitaly/comp-m2 <options>
$ ./comp --non-interactive examples/fibonacci.cm2
-------* 1
-------* 1
------*- 2
------** 3
-----*-* 5
----*--- 8
...
$ echo "3 4" | ./comp examples/multiply.cm2
----**-- 12
$ ./comp --char-output examples/hello-world.cm2
Hello world
$ echo "Hello world" | ./comp --filter examples/to-upper-case.cm2
HELLO WORLD
Two player game
$ ./comp compile --game examples/cat-and-mouse/
Compiled as cat-and-mouse
$ ./cat-and-mouse
##################
# #
# C #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# m #
# #
##################
Check out the blueprint of Mark III model.