• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created over 9 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example of CPU simulation in software

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

Author

More Repositories

1

mini_gzip

mini_gzip - embeddable, minimal, in-memory GZIP API
C
111
star
2

lastpass-ssh

SSH key management with LastPass
Ruby
110
star
3

kmnsim

Koszek-Matyja Network Simulator. Specify network architecture in a simple configuration file and run network simulations.
C
59
star
4

ncurses_guide

NCurses Examples from the book "Programmer's Guide to NCurses" with improvements and fixes
C
53
star
5

synology

My Synology automation scripts. Making Synology NAS command line usable
Shell
53
star
6

book-real-world-haskell

Real World Haskell Source Code
Shell
50
star
7

flviz

FLVIz - Finite Automata Simulator written in QT/Graphviz
HTML
36
star
8

mini_printf

mini_printf - minimal, self-contained and verified printf()
C
34
star
9

cweb

The CWEB System of Structured Documentation
C
29
star
10

lastpass-ansible

Unlock Ansible Vault with LastPass
Ruby
23
star
11

yc_interview

YC Interview Questions
14
star
12

libxbf

Xilinx Bitstream Format Library. Easily read .bit files from C programs.
C
13
star
13

usbpush

USBpush program for "DNW" U-boot protocol support in FriendlyARM/QT2410/OrigenBoard boards
C
8
star
14

sensorama-ios

Sensorama for iOS
Objective-C
8
star
15

book-programming-ruby

Source Code for Programming Ruby (2nd edition)
Ruby
7
star
16

freebsd_netfpga

FreeBSD NetFPGA driver
C
5
star
17

macb

Mac and iOS build tool
Ruby
4
star
18

edu_valgrind

Valgrind HOWTO and Examples
Makefile
4
star
19

stay_offline

Stuff for iPad/iPhone reading/listening/watching offline
Ruby
3
star
20

me

Wojciech Koszek's home page and blog
HTML
3
star
21

ruby_packages

Ruby packages built for Ubuntu
Ruby
3
star
22

tools

Handy tools and useful scripts for the command line
Shell
3
star
23

geom_sunx86label

FreeBSD GEOM class for Solaris x86 disk labels
C
2
star
24

fxload

fxload from Linux Hotplug project
C
2
star
25

godaddycli

[BROKEN] Command Line Interface to GoDaddy.com based on PyGoDaddy Library
Python
2
star
26

cs193p

Stanford's CS193p Class Source Code
Objective-C
2
star
27

shroud

Shroud
C
1
star
28

netgear_recovery

Netgear Firmware Recovery via TFTP
1
star
29

uitestviewer

pytest result test viewer
1
star
30

msgr

msgr
Go
1
star
31

edu_objc

Objective C exercises to understand the semantics of some APIs.
Objective-C
1
star
32

unix_plugin

unix_plugin - skeleton for UNIX plugin mechanism
C
1
star
33

rmdups

Remove duplicate copies of files from your messy backup
Go
1
star
34

sentperm

SentPerm - sentence permutation program
C
1
star
35

sensorama-datapath

Sensorama Datapath
PHP
1
star
36

usb_relay

usb_relay - JS283 relay controller
C
1
star
37

travis_deploy

My Travis Deployment environment
Shell
1
star
38

printf_binary

printf_binary plugin for FreeBSD printf implementation
C
1
star
39

vmshow

VMshow - Virtual memory statistics tool based on FreeBSD's KVM API
C
1
star
40

libcla

Command Line Argument library for easier argument parsing and usage screen generation.
C
1
star
41

zimcat

cat for ZIM file format archives
Go
1
star
42

hardware

Wojciech's hardware bits and Verilog snippets.
Verilog
1
star
43

friends

Programs written for friends, mostly during out CS studies
C++
1
star
44

edu_ruby

Ruby Educational Examples. Result of my attempt to get better at Ruby. I studied from 3 books: Programming Ruby, Ruby Programming and Teach yourself Ruby in 21 days.
Ruby
1
star
45

puzzles

Various programming puzzles
C
1
star
46

drums

My repository related to my snare drum and drumset interests
Verilog
1
star
47

sensorama.org

Sensorama website: what you see on sensorama.org
HTML
1
star
48

rcd

RCD, IP address obfuscator, for some strange reason written in C.
Perl
1
star
49

sensorama

Sensorama: understanding sensor data
Java
1
star
50

unsaver

Screen Saver Killer for UNIX, written in Literate Programming
C
1
star