-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.vhd
78 lines (65 loc) · 1.75 KB
/
alu.vhd
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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 15.04.2014 16:07:47
-- Design Name:
-- Module Name: P1d - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_Arith.ALL;
use IEEE.STD_LOGIC_Signed.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ALU is
Port ( a : in STD_LOGIC_VECTOR (31 downto 0);
b : in STD_LOGIC_VECTOR (31 downto 0);
control : in STD_LOGIC_VECTOR (2 downto 0);
zero : out STD_LOGIC;
result : out STD_LOGIC_VECTOR (31 downto 0));
end ALU;
architecture Behavioral of ALU is
signal aux : STD_LOGIC_VECTOR (31 downto 0);
begin
process(a, b, control)
begin
case control is
when "000" => aux <= a and b;
when "001" => aux <= a or b;
when "010" => aux <= a + b;
when "110" => aux <= a - b;
when "111" =>
if(a<b) then
aux <= x"00000001";
else aux <= x"00000000";
end if;
when "100" => aux <= b(15 downto 0) & x"0000";
when others => aux <= x"00000000";
end case;
end process;
result <= aux;
process(aux)
begin
if(aux = x"00000000") then
zero <= '1';
else zero <= '0';
end if;
end process;
end Behavioral;