Skip to content
/ yatch Public

A machine code interpreter for RISC-V in C++.

License

Notifications You must be signed in to change notification settings

fuzzymf/yatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yatch

Description

A machine code interpreter for RISC-V, in C++. This attempts at simulating the execution of a RISC-V machine code program. The program reads the machine code from a file, and executes it. The program is capable of executing the following instructions:

Features

  • Supports R-type instructions: add, sub, and, or, xor, sll, srl, sra, slt, sltu
  • Supports I-type instructions: addi, andi, ori, xori, slti, sltiu
  • Supports load and store instructions: lb, lh, lw, lbu, lhu, sb, sh, sw
  • Supports branch instructions: beq, bne, blt, bge, bltu, bgeu
  • Supports jump instructions: jal, jalr
  • Supports upper immediate instructions: lui, auipc
  • Single-stage core simulation
  • Five-stage core simulation (WIP)

Setup

Prerequisites

  • C++ compiler (e.g., g++)
  • Make (optional, for convenience)

Building the Project

  1. Clone the repository:

    git clone https://github.com/fuzzymfx/yatch.git
  2. Compile the project:

    g++ -std=c++20 -o .dist/yatch_simulator src/main.cpp 
  3. Alternatively, you can use a Makefile (if provided):

    make

Usage

  1. Prepare the memory files:

    • imem.txt: Contains the instruction memory.
    • dmem.txt: Contains the data memory.
  2. Run the interpreter:

    	./.dist/yatch_simulator src/input
  3. Follow the prompts to provide the path to the memory files if not specified as a command-line argument.

Memory Files Format

  • imem.txt: Each line represents an 8-bit instruction memory value in binary format.
  • dmem.txt: Each line represents an 8-bit data memory value in binary format.

Output

  • The state of the register file after each cycle is written to RFResult.txt.
  • The state of the data memory after execution is written to DmemSS_DMEMResult.txt.

Example

imem.txt

00000000 00000000 00000000 10000011 00000000 01000000 00000001 00000011 00000000 00100000 10000001 10110011 00000000 00110000 00100100 00100011 11111111 11111111 11111111 11111111

dmem.txt

01010101 01010101 01010101 01010101 00110011 00110011 00110011 00110011

Liscense

This project is licensed under the MIT License. See the LICENSE file for details.

References

Releases

No releases published

Packages

No packages published