Doug Domke
Published © GPL3+

A Beginner's Guide to FPGAs - Part 2

We are going to build an 8 Bit Arithmetic Logic Unit, the Heart of a computer CPU - it's surprisingly easy with a FPGA!

IntermediateFull instructions provided4 hours158
A Beginner's Guide to FPGAs - Part 2

Things used in this project

Hardware components

Alchitry Au FPGA Kit
×1

Software apps and online services

Alchitry Labs

Story

Read more

Schematics

None Required

Code

ALU Module

Verilog
Actual language is Lucid, similar to Verilog
module alu (
    input regA[8],
    input regB[8],
    input opCode[8],
    output regOut[16]
  ) {

  always {
    case(opCode){
      0: regOut = regA + regB;   // opcode 0 - Add A and B
      1: regOut = regA - regB;   // opcode 1 - Subtract B from A
      2: regOut = regA & regB;   // opcode 2 - AND A and B
      3: regOut = regA | regB;   // opcode 3 - OR A and B 
      4: regOut = regA ^ regB;   // opcode 4 - XOR A and B
      5: regOut = regA << 1;     // opcode 5 - Shift A left
      6: regOut = regA >> 1;     // opcode 6 - Shift A right
      7: regOut = ~ regA;        // opcode 7 - NOT A
      8: regOut = regA + 1;      // opcode 8 - Increment A 
      9: regOut = regA - 1;      // opcode 9 - Decrement A
      10: regOut = regA * regB;  // opcode 10 - Multiply B * A
      11: regOut = regB / regA;  // opcode 11 - Divide B by A
    default: regOut = 0 ;        // blank display
    }
  }
}

Credits

Doug Domke
39 projects • 112 followers
Contact

Comments

Please log in or sign up to comment.