devdjan / simpleCPU

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a just a small realisation of the computer described in Computer Science: An overview (Sixth Edition) by by J.G. Brookshear.

It is very buggy and fragile but it will run the example programs/exercises described in the book, in the form of ROMS assembled by the small assembler included in this package

Notes

I used this as an educational exercise to give me a refresher on how basic computers work. This is by no means a correct implementation, just my initial interpretation of what is described in the book.

Usage

./machine roms/add.rom
  • The -p flag will pause the machine after each CPU cycle
  • The -d flag will dump the state of the machine after each CPU cycle

Example

The following program will add two numbers together and store the result in memory

LDV 102
LDV 203
ADD 312
STO	3FF
HLT 000

assembler/assembler -i add.s -o add.rom
./machine add.rom

Specification

  • 256 bytes of memory
  • 16 general purpose registers (each one byte in size)
  • 1 instruction register (two bytes in size)
  • 1 program counter (one byte in size)
  • Memory addressing is simple.
  • CPU has no clock to regulate it
  • No floating point implementation
  • No support for overflow/carry flags
  • ROMs are loaded and stored at memory address 0x00
  • Basic instruction set
Table: The small instruction set for our machine language
Op-code Operand Description
1 R X Y LOAD the register R with the data found in memory cell with address XY
2 R X Y LOAD the register R with the value XY
3 R X Y STORE the value in register R in the memory cell with address XY
4 0 R S MOVE the value in register R to the register S
5 R S T ADD the values in registers S and T and store the result in register R
7 R S T OR the values in registers S and T in store the result in register R
8 R S T AND the values in registers S and T in store the result in register R
9 R S T XOR the values in registers S and T in store the result in register R
B R X Y JUMP to the instruction located in the memory cell XY if the value in register R is equal to the value in register 0
C 0 0 0 HALT execution

License

Do what you want

About


Languages

Language:Go 97.5%Language:Assembly 2.5%