Skip to content

Nikindrik/EVM-for-assembler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

EVM-for-assembler

This project implements an assembler and interpreter for an **Educational Virtual Machine (EVM)**. The EVM is designed to process a predefined instruction set, enabling efficient testing and execution of programs for educational purposes.

The system includes:

  1. Assembler: Translates human-readable assembly instructions into machine code (binary format).
  2. Interpreter: Executes the binary program on the virtual machine and produces memory-based results.

โœจ Features

  • Instruction Support: Implements essential EVM commands:
    • Load constant (198)
    • Read memory (67)
    • Write memory (244)
    • Subtract (103)
  • File Input/Output:
    • Reads assembly source code in a custom format.
    • Produces binary files, logs (CSV format), and result files (CSV format).
  • Flexible Command-line Interface: Supports options for input/output files, logging, and memory slicing.
  • Custom Memory Management: Handles a 256-byte virtual memory model with configurable slices.

๐Ÿ“˜ Installation and running

git clone https://github.com/Nikindrik/EVM-for-assembler
python -m venv venv

For windows

.\venv\Scripts\activate

For linux/UNIX/MAC

source venv/bin/activate

Run

python main.py assemble <path_to_input.txt> <path_to_output.bin> --log_file <path_to_log.csv>
python main.py interpret <path_to_output.bin> <path_to_result.csv> --memory_range=0:10

Example

input.txt

A=198,B=2,C=352
A=67,B=17,C=459,D=6
A=244,B=22,C=28
A=103,B=15,C=18,D=21

Run

python main.py assemble source/input.txt source/output.bin --log_file source/log.csv
python main.py interpret source/output.bin source/result.csv --memory_range=0:10

๐Ÿ“‘ Instruction Format

Assembly Commands

The following table summarizes the EVM's supported instructions:

Command Opcode Size (bytes) Description
Load constant 198 6 Loads a constant into a memory register
Read memory 67 4 Reads a value from memory using a base address and offset
Write memory 244 3 Writes a register's value to a memory location
Subtract 103 3 ubtracts two register values and stores the result in memory

๐Ÿ–ผ๏ธ Results Gallery

img.png

img.png

img.png

img.png

img.png

About

Educational virtual machine for assembler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages