VHDL code for 4-bit ALU
30/4/17, 12*37 am
FPGA Video Tutorial VHDL VHDL Video Tutorial Xilinx Tutorial Altera Tutorial Simulation Tutorial
"
Create Profile
Online VHDL and FPGA Tutorials
VHDL
! 4
VHDL code for 4-bit ALU BY ADMIN · PUBLISHED MAY 19, 2014 · UPDATED MAY 23, 2016
ALU’s comprise the combinational logic that implements logic operations such as AND, OR, NOT gate and arithmetic operations, such as Adder, Subtractor. Functionally, the operation of typical ALU is represented as shown in diagram http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
VHDL code for 4-bit ALU
Page 1 of 11
30/4/17, 12*37 am
below,
Functional Description of 4-bit Arithmetic Logic Unit Controlled by the three function select inputs (sel 2 to 0), ALU can perform all the 8 possible logic operations
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 2 of 11
VHDL code for 4-bit ALU
30/4/17, 12*37 am
VHDL Code for 4-bit ALU 1 2 3 4 5 6 7 8
library IEEE; use IEEE.STD_LOGIC_1164.ALL ALL; use IEEE.NUMERIC_STD.ALL ALL; entity alu is Port ( inp_a : in signed(3 downto 0); inp_b : in signed(3 downto 0); sel : in STD_LOGIC_VECTOR (2 downto 0);
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
VHDL code for 4-bit ALU
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
Page 3 of 11
30/4/17, 12*37 am
out_alu : out signed(3 downto 0)); end alu; architecture Behavioral of alu is begin process process(inp_a, inp_b, sel) begin case sel is when "000" => out_alu<= inp_a + inp_b; --addition when "001" => out_alu<= inp_a - inp_b; --subtraction when "010" => out_alu<= inp_a - 1; --sub 1 when "011" => out_alu<= inp_a + 1; --add 1 when "100" => out_alu<= inp_a and inp_b; --AND gate when "101" => out_alu<= inp_a or inp_b; --OR gate when "110" => out_alu<= not inp_a ; --NOT gate when "111" => out_alu<= inp_a xor inp_b; --XOR gate when others => NULL NULL; end case case; end process process; end Behavioral;
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 4 of 11
VHDL code for 4-bit ALU
30/4/17, 12*37 am
Testbench VHDL Code for 4-Bit ALU 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
LIBRARY ieee; USE ieee.std_logic_1164.ALL ALL; USE ieee.numeric_std.ALL ALL; ENTITY Tb_alu IS END Tb_alu; ARCHITECTURE behavior OF Tb_alu IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT alu PORT PORT( inp_a : IN signed(3 downto 0); inp_b : IN signed(3 downto 0); sel : IN std_logic_vector(2 downto 0); out_alu : OUT signed(3 downto 0) ); END COMPONENT COMPONENT; --Inputs signal inp_a : signed(3 downto 0) := (others others => signal inp_b : signed(3 downto 0) := (others others => signal sel : std_logic_vector(2 downto 0) := (others others --Outputs signal out_alu : signed(3 downto 0);
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 5 of 11
VHDL code for 4-bit ALU
30
Shares
23
4
1
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
30/4/17, 12*37 am
BEGIN -- Instantiate the Unit Under Test (UUT) uut: alu PORT MAP ( inp_a => inp_a, inp_b => inp_b, sel => sel, out_alu => out_alu ); -- Stimulus process stim_proc: process begin -- hold reset state for 100 ns. wait for 100 ns; -- insert stimulus here inp_a <= "1001"; inp_b <= "1111"; sel <= "000"; wait for 100 sel <= "001"; wait for 100 sel <= "010"; wait for 100 sel <= "011"; wait for 100 sel <= "100"; wait for 100
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
ns; ns; ns; ns; ns; Page 6 of 11
VHDL code for 4-bit ALU
61 62 63 64 65 66 67 68
30/4/17, 12*37 am
sel <= "101"; wait for 100 ns; sel <= "110"; wait for 100 ns; sel <= "111"; end process process; END END;
Simulation Result for 4-bit ALU
Tags:
ALU VHDL code
Download Post as PDF
arithmetic and loogic unit vhdl code
$ YOU MAY ALSO LIKE... http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 7 of 11
VHDL code for 4-bit ALU
30/4/17, 12*37 am
!0
Synchronous and Asynchronous Reset VHDL
!0
!2
VHDL 4 to 1 Mux (Multiplexer)
VHDL Code for Flipflop – D,JK,SR,T
LAST UPDATED MAY 19, 2016
LAST UPDATED MAY 20, 2016
LAST UPDATED JUNE 8, 2016
4 RESPONSES ! Comments 4 Admin ⋆
&
% Pingbacks 0
May 25, 2014 at 10:36 am
Soon, we will come up with step by step procedure to download bit in FPGA for all VHDL code and verify it. Reply user
&
October 5, 2015 at 3:17 pm
Temp <= std_logic_vector((unsigned("0" & Nibble1) + unsigned(Nibble2))); i need an explanation to the above usage of "0" & nibble1….means i want to know the clear intention of the statement…..hope i will get a response
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 8 of 11
VHDL code for 4-bit ALU
30/4/17, 12*37 am
thank you Reply Admin ⋆
&
February 2, 2016 at 2:34 am
‘0’ is concatenated with nibble because the output result give carry at MSB. Reply
malu
&
October 14, 2016 at 10:16 am
i am not understand the program,another method will tri sir. Reply
LEAVE A REPLY Comment
Name *
Email *
Website
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
Page 9 of 11
VHDL code for 4-bit ALU
30/4/17, 12*37 am
Post Comment Notify me of follow-up comments by email. Notify me of new posts by email.
WELCOME TO ALL ABOUT FPGA
Hi, If you are a beginner, looking to learn VHDL Programming and FPGA Design, this tutorials
SUBSCRIBE TO ALL ABOUT FPGA
Enter your email address to receive
All About FPGA 3,295 likes
notifications of new Tutorial by email.
on VHDL and FPGA basics is a perfect match to
Email Address
getting started. This tutorial consist of various
Subscribe
Share
Like Page
uses and features of the FPGA. It shows VHDL
Be the first of your friends to like this
Programming written and explained with digital circuit development. Through many examples, you can be an expert in FPGA in notime. You can reach us through allaboutfpga at gmail dot com
∠ All About FPGA © 2017. All Rights Reserved.
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
) + + Page 10 of 11
VHDL code for 4-bit ALU
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/
30/4/17, 12*37 am
Page 11 of 11