Lab 13
Lab 13
Batch: BSEE 22
Signature: __________________________
13.1. Introduction
This lab requires the students to use their knowledge of digital systems thereby performing the implementation key digital circuits
such as combinational circuits. The students specifically are required to implement Arithmetic Logic Unit (ALU) in Verilog.
13.2. Objectives
The aforementioned ALU should perform
• Addition
• Subtraction
• Bitwise and
• Bitwise or
• Bitwise XOR
Report
"Verilog Implementation of a Comprehensive Arithmetic Logic Unit (ALU) with
Multi-Function Capabilities"
Introduction
ALU_Testbench Module:
This module serves as a testbench for the MAIN_ALU module. It provides inputs to the ALU and observes the results for different
operations. The specified operations include addition, subtraction, bitwise AND, bitwise OR, and bitwise XOR. The testbench
includes a clock (Clk), inputs (X, Y, ALUOp, Cin), and outputs (Output, Cout).
Adder Module:
This module implements a 4-bit adder. The sum output represents the sum of two inputs (x and y) along with a carry-in (cin). The
cout output indicates the carry-out from the most significant bit.
MAIN_ALU Module:
The main Arithmetic Logic Unit (ALU) module incorporates various components to perform different operations based on the given
ALUOp input. It includes an adder (Task1), a subtractor (Task2), logic to select operations based on ALUOp, and outputs (Output,
Cout). The ALU operates on the rising edge of the clock (Clk).
Decoder Module:
The decoder module takes a 3-bit input (A) and produces an 8-bit output (Y). The output represents a binary selection based on the
input. It is used to convert the 3-bit ALUOp into an 8-bit control signal for the ALU operations.
FlipFlop Module:
This module implements a simple D flip-flop. The output Q is updated on the rising edge of the clock (CLK) based on the input
data (D).
Subtractor Module:
Similar to the Adder module, this module implements a 4-bit subtractor. It calculates the difference (Diff) and the borrow-out
(Yout) based on the inputs (X, Y, Yin).
LogicGates Module:
This module performs basic logic operations on 4-bit inputs X and Y. It produces outputs for AND (AND_out), OR (OR_out), and
XOR (XOR_out) operations.
Summary:
The provided Verilog code collectively represents a comprehensive implementation of an Arithmetic Logic Unit (ALU) with the
capability to perform addition, subtraction, bitwise AND, OR, and XOR operations. The design is modular, with separate modules
for different components, enhancing readability and maintainability. The testbench (ALU_Testbench) allows for the validation of
the ALU functionality under various scenarios.
The importance of the problem addressed in this lab lies in its practical application and relevance to digital systems and computer
architecture. Here are some key points highlighting the significance of implementing an Arithmetic Logic Unit (ALU) with the
specified functionalities:
1. Core Component of CPUs:
• The ALU is a fundamental building block of central processing units (CPUs) in computers. It performs essential
arithmetic and logical operations required for the execution of programs and processing of data.
2. Versatile Operation:
• By incorporating addition, subtraction, bitwise AND, OR, and XOR operations, the designed ALU becomes a
versatile component capable of handling a wide range of computational tasks. This versatility is crucial for
supporting diverse applications and algorithms.
3. Digital System Design Understanding:
• The lab task requires students to apply their knowledge of digital systems and combinational circuits. Designing
an ALU involves understanding how different components work together to execute operations, contributing to a
deeper comprehension of digital system design principles.
4. Coding and Implementation Skills:
• Implementing the ALU in Verilog challenges students to translate theoretical knowledge into practical coding
skills. This hands-on experience is invaluable for future engineers and computer scientists, as it enhances their
ability to design and implement complex digital systems.
5. Problem-Solving Skills:
• Students need to address the challenge of integrating various components, including adders, subtractors, logic
gates, decoders, and flip-flops, to create a functional ALU. This problem-solving exercise enhances their
analytical and design skills.
6. Understanding Opcode-Based Operation:
• The inclusion of a 3-to-8 decoder to select operations based on Opcode input reflects real-world CPU design. This
aspect of the lab emphasizes the importance of understanding how control signals and decoders are used to execute
different instructions in a CPU.
7. Group Collaboration and Individual Accountability:
• Allowing group work encourages collaboration, simulating real-world scenarios where engineers often work in
teams. However, individual manual submissions promote accountability, ensuring that each student understands
and can independently demonstrate their knowledge.
8. Time Management:
• The requirement to complete all tasks within the lab time emphasizes the importance of time management in
engineering projects. Meeting deadlines is a crucial skill in professional settings.
In summary, this lab tackles a fundamental problem in computer engineering, providing students with hands-on experience in
designing and implementing a crucial component of digital systems. The skills developed in this lab are directly applicable to real-
world scenarios in computer architecture and digital system design.
2. Adder Module:
• Inputs:
• x and y: 4-bit input operands.
• cin: Carry input.
• Outputs:
• sum: 4-bit sum output.
• cout: Carry output.
• Behavior:
• Computes the sum and carry-out using bitwise XOR and AND operations.
3. MAIN_ALU Module:
• Inputs:
• X, ALUOp, Y: 4-bit input operands and 3-bit operation code.
• Cin: Carry input.
• Clk: Clock signal.
• Outputs:
• Output: 4-bit output result.
• Cout: Carry output.
• Behavior:
• Utilizes a decoder to choose the appropriate operation based on the ALUOp.
• Instantiates an adder (Task1) and a subtractor (Task2).
• Outputs the result and carry based on the selected operation.
4. Decoder Module:
• Inputs:
• A: 3-bit input representing ALU operation code.
• Outputs:
• Y: 8-bit output representing the control signal for ALU operations.
• Behavior:
• Decodes the 3-bit input to an 8-bit output, where each bit corresponds to a specific ALU operation.
5. FlipFlop Module:
• Inputs:
• D: Data input.
• CLK: Clock signal.
• Outputs:
• Q: Flip-flop output.
• Behavior:
• Updates the output Q on the rising edge of the clock (CLK) based on the input data (D).
6. Subtractor Module:
• Inputs:
• X and Y: 4-bit input operands.
• Yin: Borrow input.
• Outputs:
• Diff: 4-bit difference output.
• Yout: Borrow output.
• Behavior:
• Computes the difference and borrow-out using bitwise XOR and AND operations.
7. LogicGates Module:
• Inputs:
• X and Y: 4-bit input operands.
• Outputs:
• AND_out, OR_out, XOR_out: Outputs of bitwise AND, OR, and XOR operations.
• Behavior:
• Performs basic logic operations on the input operands.
These modules collectively create a modular and functional ALU, with a testbench (ALU_Testbench) to validate its correct
behavior under various scenarios. Each module contributes to the overall functionality of the ALU, implementing specific
components and operations in a modular and organized manner.
CODES:
13.4.2. Results
13.4.3. Conclusion
In this lab, a comprehensive implementation of an Arithmetic Logic Unit (ALU) in Verilog has been achieved. The designed ALU
is capable of performing key operations such as addition, subtraction, bitwise AND, OR, and XOR. The modular approach to the
design, using separate modules for different components, enhances readability, maintainability, and overall understanding of the
digital system.
The key components of the ALU include adders, subtractors, logic gates, decoders, and flip-flops. These components work together
to execute operations based on the specified 3-bit ALU operation code (ALUOp). The design adheres to good coding practices,
incorporating meaningful names for modules, signals, and operations.
A testbench (ALU_Testbench) has been provided to verify the correct functionality of the ALU under different scenarios. The test
cases include addition, subtraction, bitwise AND, OR, and XOR operations, ensuring that the ALU operates as expected.
The use of a decoder (Decoder module) facilitates the interpretation of the 3-bit ALU operation code, converting it into an 8-bit
control signal for the ALU operations. This approach allows for extensibility, making it easier to add new operations in the future.
In summary, this lab provides students with valuable hands-on experience in designing a versatile ALU, a fundamental component
of digital systems and computer architecture. The modular design, thoughtful use of control signals, and the inclusion of a testbench
contribute to a well-rounded learning experience in digital system design and Verilog programming. Students are encouraged to
further explore and optimize the design, extending its capabilities or implementing additional features for a deeper understanding
of digital circuit design.
Assessment Rubric
Method:
Lab report evaluation and instructor observation during lab sessions.