Skip to content

lhalf/risc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

risc

RISC machine and simple program parser implemented in C++.

Dependencies

You will need Podman to run commands. (https://podman.io/docs/installation)

Running commands

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".

Notes

There is a simple program parser for loading programs from .txt files, the following files are therefore not part of the cpu implementation:

Implementation

Registers & flags

  • 8 general purpose 32-bit data registers R0-R7
  • 1 status flag compare_equal

Memory

  • Fixed array of up to 256 instructions
  • Fixed array of 256 32-bit data addresses

Other

  • There is a limit of 50,000 executed instructions, after which HALT is called. This is to prevent unintended recursion when testing programs.

Instructions

HALT

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.

CMP

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.

JMP

Example: JMP 10

Jumps the program counter to the specified address independent of status flags.

JMP_EQ

Example: JMP_EQ 10

Jumps the program counter to the specified address only if the compare_equal status flag is true.

LOAD

Example: LOAD 10, R0

Loads the contents at memory address 10 into R0.

STORE

Example: STORE R0, 10

Stores the contents of R0 at memory address 10.

ADD

Example: ADD R0, R1, R2

Adds the contents of R0 to R1 and places in R2.

SUB

Example: SUB R0, R1, R2

Subtracts the contents of R1 from R0 and places in R2.

About

RISC machine and simple program parser implemented in C++.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published