8-bit Arithmetic Logic Unit


Problem Statement: Design and simulate a 8-bit ALU.


Introduction to ALU

An arithmetic logic unit (ALU) is a digital circuit used to perform arithmetic and logic operations. It represents the fundamental building block of the central processing unit (CPU) of a computer. Modern CPUs contain very powerful and complex ALUs. In addition to ALUs, modern CPUs contain a control unit (CU).

Most of the operations of a CPU are performed by one or more ALUs, which load data from input registers. A register is a small amount of storage available as part of a CPU. The control unit tells the ALU what operation to perform on that data, and the ALU stores the result in an output register. The control unit moves the data between these registers, the ALU, and memory.

Here, we will design an 8-bit ALU which performs different set of arithmetic and logical operations based on the select input s.

Implementation Table of 8-bit ALU

The below table indicates the Arithmetic and Logical operations performed based on the select input s and also the output y obtained for for the given set of input a and b. This ALU is designed using arithmetic and logical operations mentioned in the table below.

Arithmetic OperationsLogical Operations
AdditionBitwise AND & NAND
SubtractionBitwise OR & NOR
MultiplicationBitwise NOR & XNOR
DivisionShift Right & Shift Left
IncrementRotate Right & Rotate Left
Decrement

Table 1: Implementation Table of 8-bit ALU
soperationabycarryzero
0000Addition111011101110111000000000 1101110010
0001Subtraction111011101110111000000000 0000000001
0010Increment111011101110111000000000 1110111100
0011Decrement111011101110111000000000 1110110100
0100Multiplication111011101110111011011101 0100010000
0101Division111011101110111000000000 0000000100
0110Bitwise AND111011101110111000000000 1110111000
0111Bitwise OR111011101110111000000000 1110111000
1000Bitwise XOR111011101110111000000000 0000000001
1001Bitwise NAND111011101110111000000000 0001000100
1010Bitwise NOR111011101110111000000000 0001000100
1011Bitwise XNOR111011101110111000000000 1111111100
1100Shift Left111011101110111000000000 1101110010
1101Shift Right111011101110111000000000 0111011100
1110Rotate Right111011101110111000000000 0111011100
1111Rotate Left111011101110111000000000 1101110100

Implementation of 8-bit ALU

To implement 8-bit ALU design, follow these steps.

  1. Create a new Verilog file and start writing code for 8-bit ALU as given below and save the file. Keep the file name as ALU.

  2. We will use testbench to verify the output of this design. Create a new Verilog file and type the testbench code provided below and Save the file with the same name as the module name.

  3. Compile the code and check for any syntax errors using the below command.

    iverilog ALU.v tb_ALU.v -o ALU
    
  4. If there are no errors, use the below command for running the simulation.

    vvp ALU
    

    You will see the values of signals being monitored across each clocktick.

  5. If all looks well, use the below command for viewing the waveform. Add the signals from tb_ALU design to the window to view the simulation output as shown in below image.

    gtkwave alu.vcd