VHDL Code For 4-Bit ALU
VHDL Code For 4-Bit ALU
Create Profile
Online VHDL and FPGA Tutorials
VHDL ! 4
ALUs comprise the combinational logic that implements logic operations such as
AND, OR, NOT gate and arithmetic operations, such as Adder, Subtractor.
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 1 of 11
below,
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
1 library IEEE;
2 use IEEE.STD_LOGIC_1164.ALL
ALL;
3 use IEEE.NUMERIC_STD.ALL
ALL;
4
5 entity alu is
6 Port ( inp_a : in signed(3 downto 0);
7 inp_b : in signed(3 downto 0);
8 sel : in STD_LOGIC_VECTOR (2 downto 0);
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 3 of 11
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
1 LIBRARY ieee;
2 USE ieee.std_logic_1164.ALL
ALL;
3 USE ieee.numeric_std.ALL
ALL;
4
5 ENTITY Tb_alu IS
6 END Tb_alu;
7
8 ARCHITECTURE behavior OF Tb_alu IS
9
10 -- Component Declaration for the Unit Under Test (UUT)
11
12 COMPONENT alu
13 PORT
PORT(
14 inp_a : IN signed(3 downto 0);
15 inp_b : IN signed(3 downto 0);
16 sel : IN std_logic_vector(2 downto 0);
17 out_alu : OUT signed(3 downto 0)
18 );
19 END COMPONENT
COMPONENT;
20
21
22 --Inputs
23 signal inp_a : signed(3 downto 0) := (others
others =>
24 signal inp_b : signed(3 downto 0) := (others
others =>
25 signal sel : std_logic_vector(2 downto 0) := (others
others
26
27 --Outputs
28 signal out_alu : signed(3 downto 0);
29
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 5 of 11
30 BEGIN
31
32 -- Instantiate the Unit Under Test (UUT)
33 uut: alu PORT MAP (
34 inp_a => inp_a,
35 inp_b => inp_b,
36 sel => sel,
37 out_alu => out_alu
38 );
39
40 -- Stimulus process
41 stim_proc: process
42 begin
43 -- hold reset state for 100 ns.
44 wait for 100 ns;
30 45
Shares
46 -- insert stimulus here
47
48 inp_a <= "1001";
23
49 inp_b <= "1111";
50
4 51 sel <= "000";
52 wait for 100 ns;
53 sel <= "001";
1 54 wait for 100 ns;
55 sel <= "010";
56 wait for 100 ns;
57 sel <= "011";
58 wait for 100 ns;
59 sel <= "100";
60 wait for 100 ns;
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 6 of 11
VHDL code for 4-bit ALU 30/4/17, 12*37 am
Tags: ALU VHDL code arithmetic and loogic unit vhdl code
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 7 of 11
!0 !0 !2
4 RESPONSES
! Comments 4 % Pingbacks 0
Soon, we will come up with step by step procedure to download bit in FPGA for all VHDL code
and verify it.
Reply
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
Reply
Reply
LEAVE A REPLY
Comment
Name * Email *
Website
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 9 of 11
Post Comment
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 30/4/17, 12*37 am
http://allaboutfpga.com/vhdl-code-for-4-bit-alu/ Page 11 of 11