This guide provides the steps necessary to compile the CPU design files and run a simulation using ModelSim or QuestaSim (which typically use the vlog and vsim commands).
-
ModelSim / QuestaSim must be installed and configured on your system, with vlog and vsim available in your terminal path.
-
A compiled binary file (
program.bin) must be available. This file is generated by the assembler/compiler and contains the raw machine code instructions that the CPU will execute.
First, use your compiler and assembler to generate the machine code binary file. This file must be named program.bin and should be placed inside the cpu/ directory for the testbench to automatically locate and load it into the instruction memory.
./fsrvc path/to/your/program.fs --emit-bin program.bincp program.bin ./cpu/Navigate to the root directory of your project and use vlog to compile all necessary SystemVerilog source files into a library (usually work).
vlog -sv ./cpu/*.svThis command compiles the files in the cpu/ directory (which should contain the CPU core, the testbench, and the memory model that handles loading program.bin).
Start the simulator and run the top-level testbench module.
vsim -c -do "run -all; quit" cpu_tbRunning with Waveform Viewer If you want to view the signals in the waveform window, omit the -c (command line) and quit commands:
vsim main_tbThe simulation will execute your program.bin file, and the results (such as register file contents or final output) will be displayed in the simulator console or logged to a file as defined by the testbench