项目作者: skni-kod

项目描述 :
Simple ram machine interpreter
高级语言: C
项目地址: git://github.com/skni-kod/Ram-machine.git
创建时间: 2019-11-21T18:53:39Z
项目社区:https://github.com/skni-kod/Ram-machine

开源协议:MIT License

下载


Ram-machine


Build status
Closed pull requests
License
Documentation

Program is a simple implementation of RAM machine.

Documentation

Code documentation is here.

Program

The ram-machine program is a set of simple instructions which can be executed by the interpeter. It should be provided as a text file using the -code (PATH) argument. It is important to note that the program parser skips all the spaces and newlines to avoid any unnecessary errors.

The program should be written with lines of code described as below:

[JUMP label], instruction, access modifier, argument, [comment];

Example program for abs is listed below:

  1. , READ , , 0 , Read value to accumulator;
  2. , JGTZ , , NOABS, If accumulator is greather than 0 jump to NOABS;
  3. , STORE, , 1 , Store accumulator to register 1;
  4. , LOAD , =, 0 , Load 0 to accumulator;
  5. , SUB , , 1 , Subtract value in register 1 from accumulator;
  6. NOABS, WRITE, , 0 , Write accumulator;
  7. , HALT , , , Stop;

More example programs can be found in instructions folder.

Input tape

Input tape should be provided as a text file with values separated by spaces, using the -input (PATH) argument.

Output tape

Output tape is by default set as the standard output, though it can be changed to be saved as a text file using the -output (PATH) argument.

Registers

Memory is made of registers. Register 0 is the accumulator. Other registers can be freely accessed. Registers are integers from 0 to count - 1. The register count is by default set to 100. The register count can be changed using the -registers (COUNT) argument.

Access modifier

The access modifier is used to specify how to handle the instruction argument. The instruction argument should be treated as follows:

  • (nothing) - register
  • = - literal
  • * - register’s value is pointer to other register

Supported instructions

List of supported instructions:
|Instruction|Access Modifier|Argument|Description|
|—-|—-|—-|—-|
|JUMP|<nothing>|argument| jump to label argument |
|JZERO|<nothing>|argument| jump to label argument if accumulator is zero |
|JGTZ|<nothing>|argument| jump to label argument if accumulator is greather than zero |
|LOAD|<nothing> or = or *|argument| load value to accumulator from argument |
|STORE|<nothing> or *|argument| store value from accumulator from argument |
|ADD|<nothing> or = or *|argument| add argument to accumulator value |
|SUB|<nothing> or = or *|argument| subtract argument from accumulator |
|MULT|<nothing> or = or *|argument| multiply accumulator by argument |
|DIV|<nothing> or = or *|argument| divide accumulator by argument |
|READ|<nothing> or *|argument| read from input tape |
|WRITE|<nothing> or = or *|argument| write to output tape |
|HALT|<nothing>|<nothing>| ends program |