0
0
VHDLprogramming~30 mins

ALU design in VHDL - Mini Project: Build & Apply

Choose your learning style9 modes available
ALU Design in VHDL
📖 Scenario: You are designing a simple Arithmetic Logic Unit (ALU) for a small digital system. The ALU will perform basic operations like addition, subtraction, AND, and OR on two 4-bit inputs.
🎯 Goal: Build a VHDL module for an ALU that takes two 4-bit inputs and a 2-bit operation selector, then outputs the 4-bit result of the selected operation.
📋 What You'll Learn
Create two 4-bit input signals named A and B.
Create a 2-bit input signal named Op to select the operation.
Implement the ALU logic to perform addition, subtraction, AND, and OR based on Op.
Output the 4-bit result on a signal named Result.
💡 Why This Matters
🌍 Real World
ALUs are the core of all processors and digital systems, performing arithmetic and logic operations on data.
💼 Career
Understanding ALU design is essential for hardware engineers and FPGA developers working on digital circuit design.
Progress0 / 4 steps
1
DATA SETUP: Define inputs and output signals
Write the VHDL code to declare a 4-bit input signal A, a 4-bit input signal B, a 2-bit input signal Op, and a 4-bit output signal Result inside an entity named SimpleALU.
VHDL
Need a hint?

Use std_logic_vector(3 downto 0) for 4-bit signals and std_logic_vector(1 downto 0) for 2-bit signals.

2
CONFIGURATION: Create architecture and signal for internal calculation
Write the VHDL code to start the architecture named Behavioral for SimpleALU and declare an internal 5-bit signal named temp_result to hold intermediate results.
VHDL
Need a hint?

Use a 5-bit vector for temp_result to hold carry or borrow bits during addition or subtraction.

3
CORE LOGIC: Implement ALU operations using a process and case statement
Inside the architecture Behavioral, write a process that triggers on changes to A, B, or Op. Use a case statement on Op to assign temp_result as follows: "00" for addition (A + B), "01" for subtraction (A - B), "10" for bitwise AND (A and B), and "11" for bitwise OR (A or B). Then assign the lower 4 bits of temp_result to Result.
VHDL
Need a hint?

Use unsigned() conversion for arithmetic operations and assign the 4-bit result to Result.

4
OUTPUT: Test the ALU by printing the result for a sample input
Write a simple testbench process inside the architecture Behavioral that assigns A = "0011", B = "0001", and Op = "00" (addition). Then output the value of Result using report statement to display the result as a string.
VHDL
Need a hint?

Use a test process to assign values and a report statement to print the result as an integer.