-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALU.vhd
More file actions
61 lines (59 loc) · 1.4 KB
/
ALU.vhd
File metadata and controls
61 lines (59 loc) · 1.4 KB
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
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity FourBitALU is
port (
A, B: in std_ulogic_vector(3 downto 0);
Q: out std_logic_vector(3 downto 0);
CTRL: in std_logic_vector(2 downto 0);
cin, reset, Clk: in std_logic;
Cout: out std_logic
);
end FourBitALU;
architecture behaviour of FourBitALU is
signal tmp: std_logic_vector(4 downto 0);
-- signal CTRL: std_logic_vector(2 downto 0);
begin
process (reset, Clk)
--variable tmp: std_logic_vector(4 downto 0) := (others => '0');
begin
if (reset = '0') then -- active low
Q <= (others => '0');
elsif (rising_edge(clk)) then
--process(A,B,CTRL)
--begin
case CTRL is
when "000" =>
Q <= A(2 downto 0) & cin;
Cout <= A(3);
when "001" =>
Q <= cin & A(3 dowto 1);
Cout <= A(0);
when "010" =>
Q <= A(2 downto 0) & '0';
Cout <= '0';
when "011" =>
Q <= '0' & A(3 dowto 1);
Cout <= '0';
when "100" =>
tmp <= ('0' & A) + ('0' & B) + ("0000" & cin);
Cout <= tmp(4);
when "101" =>
tmp <= ('0' & A) - ('0' & B) - not("0000" & cin);
Cout <= tmp(4);
when "110" =>
tmp <= ('0' & A) + ('0' & B);
Cout <= '0';
when "111" =>
tmp <= ('0' & A) - ('0' & B);
Cout <= '0';
when others =>
tmp <= (others => '0');
Cout <= '0';
end case;
end if;
--Q <= tmp(4 downto 0);
end process;
Q <= tmp(4 downto 0);
end behaviour