RISC machine and simple program parser implemented in C++.
You will need Podman to run commands. (https://podman.io/docs/installation)
Use the script ./dev/run_in_pod.sh
to run any commands.
All the commands are available in the justfile
in the top level (https://github.com/casey/just).
This means they can be easily run by doing e.g. ./dev/run_in_pod.sh "just test"
.
Use the -l
flag to see all available commands and how to use them e.g. ./dev/run_in_pod.sh "just -l"
.
There is a simple program parser for loading programs from .txt files, the following files are therefore not part of the cpu implementation:
- 8 general purpose 32-bit data registers R0-R7
- 1 status flag compare_equal
- Fixed array of up to 256 instructions
- Fixed array of 256 32-bit data addresses
- There is a limit of 50,000 executed instructions, after which HALT is called. This is to prevent unintended recursion when testing programs.
Example: HALT
Stops execution of the machine.
- If the program counter reaches the end of the instructions in memory HALT is called.
- Therefore, if JMP / JMP_EQ try to jump to a program count which does not contain an instruction HALT is called.
Example: CMP R0, R1
Compares the contents of R0 and R1, if they are the same the status flag compare_equal is set to true, otherwise it is set to false.
Example: JMP 10
Jumps the program counter to the specified address independent of status flags.
Example: JMP_EQ 10
Jumps the program counter to the specified address only if the compare_equal status flag is true.
Example: LOAD 10, R0
Loads the contents at memory address 10 into R0.
Example: STORE R0, 10
Stores the contents of R0 at memory address 10.
Example: ADD R0, R1, R2
Adds the contents of R0 to R1 and places in R2.
Example: SUB R0, R1, R2
Subtracts the contents of R1 from R0 and places in R2.