This project is a functional simulator for the custom TOY ISA v1.1 architecture. It was developed as a course project to demonstrate the principles of CPU emulation.
The simulator executes 32-bit machine code generated from a custom assembly language. It currently supports all instructions specified in the TOY ISA v1.1 documentation, including basic arithmetic, memory access, branching, and system calls for I/O and halting the machine.
The project includes two main components:
- An assembler written in Ruby, which translates TOY assembly code into a raw binary format.
- A CPU simulator written in C++, which loads and executes the binary programs.
- A C++ compiler (g++ recommended)
- CMake (version 3.15 or later)
- Ruby (for the assembler script)
Clone the repository:
git clone git@github.com:rhagewannakiss/toy-simulator.git
cd toy-simulatorConfigure and build the C++ simulator using CMake:
cmake --build build --parallel `nproc`After a successful build, the simulator executable will be located at build/toy_cpu.
The workflow consists of two stages: assembling your program and running it on the simulator.
- Assembling the Program Use the provided Ruby script to convert your .asm source file into a .bin executable binary.
Command:
ruby ./src/asm/run_assembler.rb <input_file.asm> <output_file.bin>Example:
ruby /src/asm/run_assembler.rb fib.asm fib.binThis will create fib.bin in project's root directory.
- Running the Simulator Execute the compiled simulator, providing the path to your binary file. You can also set initial register values and the starting program counter (PC) via command-line flags.
Command Syntax:
./build/toy_cpu <path_to_binary.bin> [x[reg_id]=[value]]Example: To run the fib.bin program to calculate fib(12), you need to initialize register x1:
./build/bin/toy_cpu fib.bin x1=12The simulator will execute the program until a halt syscall is encountered and then print the final state of all CPU registers.