Giter Club home page Giter Club logo

4-bit-cpu's Introduction

CPU core from logic gates

A 4-bit CPU core using only wires and logic gates. Implemented using Verilog.

Specifications

  • Register width: 4 bits
  • Instruction length: 16 bits
  • Number of instructions: 16
  • Instruction memory size: 256 bits
  • Clock period: 280 ns
  • Single cycle

Gate delays

  • AND: 3 ns
  • OR: 3 ns
  • NAND: 2 ns
  • NOR: 2 ns
  • NOT: 1 ns
  • XOR: 4 ns
  • XNOR: 5 ns

Instructions

For all instructions' machine code

  • Bits[15:8]: opcode

add regd rega regb

  • Opcode: 00000000
  • Effect: regd = rega + regb, PC += 1
  • Example: add reg0 reg1 reg2
  • Machine code
    • Bits[7:6]: unused
    • Bits[5:4]: d
    • Bits[3:2]: a
    • Bits[1:0]: b

nand regd rega regb

  • Opcode: 00000001
  • Effect: regd = rega โ†‘ regb, PC += 1
  • Example: nand reg0 reg1 reg2
  • Machine code
    • Bits[7:6]: unused
    • Bits[5:4]: d
    • Bits[3:2]: a
    • Bits[1:0]: b

move regd IMM

  • Opcode: 00000010
  • Effect: regd = IMM, PC += 1
    • IMM is a 4 bit signed immediate
  • Example: move reg0 0000
  • Machine code
    • Bits[7:6]: unused
    • Bits[5:4]: d
    • Bits[3:0]: IMM

noop

  • Opcode: 00000011
  • Effect: PC += 1
  • Example: noop
  • Machine code
    • Bits[7:0]: unused

branch JMP rega regb

  • Opcode: 00000100
  • Effect: PC = (rega == regb) ? PC + JMP : PC + 1
    • JMP is a 4 bit signed immediate
  • Example: branch 0011 reg0 reg1
  • Machine code
    • Bits[7:4]: JMP
    • Bits[3:2]: a
    • Bits[1:0]: b

Schematic

High-level schematic of datapath, generated using Intel Quartus Prime.

schematic

Getting started

This is an example of running an assembly file on the CPU. This example uses Icarus Verilog and GTKWave on Linux.

  1. Locate assembly file, i.e. ins_mem/programs/general.tass
  2. Build instruction memory module
$ pwd
<4-bit-cpu>
$ cd ins_mem/
$ ./assembler programs/general.tass
$ cd ../
  1. Build datapath module
$ pwd
<4-bit-cpu>
$ cd datapath/
$ ./build.sh
  1. Run simulation
$ pwd
<4-bit-cpu>/datapath
$ vvp testbench
  1. View waveform
$ pwd
<4-bit-cpu>/datapath
$ gtkwave test.vcd

waveform

Design files

Designs for circuits can be viewed in designs.pdf.

4-bit-cpu's People

Contributors

tom21487 avatar

Watchers

 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.