Coder Social home page Coder Social logo

basic-cpu's Introduction

Basic-CPU

This is a very simple, compact, virtual cpu written in c. It's a project for fun and learning, so feel free to play around with it to try out different ideas. Don't be surprised if you find some bugs.

You can find a video walkthrough of the cpu here:

https://www.youtube.com/watch?v=cfPDeso3XwI

Prerequisites

You'll need a c compiler that compiles to the c99 standard, and git is recommended.

Get basic-cpu

Use the following command to get the repository:

git clone https://github.com/pbohun/basic-cpu.git

Usage

Include the cpu.h file in your program and you're ready to go. You have to use the new_cpu() function to create a new cpu and free_cpu() function at the end.

Runing the tests

To compile and run the tests use the following commands:

gcc -std=c99 -o tests tests.c
./tests

Trying the example

To compile the example program use the following command:

gcc -std=c99 -o example example.c

The example program calculates 5 factorial and stores the answer in the register 0 (R0).

Writing Programs

Note that this is just a cpu. There are no mechanisms for input, output, monitors, long term storage, etc. You have to create memory for the cpu and fill it with machine code. An example of this is found in the example.c file.

Everything in the cpu is 64 bit, defined as i64 and f64 for 64 bit floating point. Most instructions involve registers. Here's an example of what a move instruction would look like in an array of memory. Note that it's designed to look a lot like assembly language.

MOV, R0, R1

Take a look at the example.c file and the tests.c file to see how to use the cpu.h library.

basic-cpu's People

Contributors

pbohun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.