-
Notifications
You must be signed in to change notification settings - Fork 1
/
alu.vhdl
40 lines (36 loc) · 1.08 KB
/
alu.vhdl
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
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.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);
out_alu : OUT signed(3 DOWNTO 0));
END alu;
ARCHITECTURE Behavioral OF alu IS
BEGIN
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;
END CASE;
END PROCESS;
END Behavioral;