Giter Site home page Giter Site logo

cpu60's Introduction

Simple CPU model written in 60 lines of code

Build Status

CPU60 is a simple CPU model written in 60 lines of C code.

It supports 8 registers and several simple instructions: mov, add, addi, sub, subi, and, andi, or, ori instructions. Following each instruction is the CPU register dump. By default input is read from the standard input.

Flag -r might be passed to simulate the proper reset of the CPU. Upon reset, all registers are filled with 0's. Without -r, the values of the registers are undefined, and your program instructions can't depend on register's content.

How to build

To build:

make

How to run

Either manually:

% ./cpu60
reg0=a7   reg1=f1   reg2=d9   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe
sub r0,r0,r0
reg0=00   reg1=f1   reg2=d9   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe sub r0,r0,r0
sub r1,r1,r1
reg0=00   reg1=00   reg2=d9   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe sub r1,r1,r1
ori r0,r0,1
reg0=01   reg1=00   reg2=d9   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe ori r0,r0,1
ori r1,r1,2
reg0=01   reg1=02   reg2=d9   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe ori r1,r1,2
add r2,r0,r1
reg0=01   reg1=02   reg2=03   reg3=2a   reg4=82   reg5=c8   reg6=d8   reg7=fe add r2,r0,r1

Or from file:

% cpu60 < file

Where file can have any valid opcodes.

How to test

To unit test the model, hit:

make test

cpu60's People

Contributors

wkoszek avatar

Watchers

James Cloos 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.