-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALU.vhd
More file actions
75 lines (69 loc) · 1.91 KB
/
ALU.vhd
File metadata and controls
75 lines (69 loc) · 1.91 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
62
63
64
65
66
67
68
69
70
71
72
73
74
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity alu is -- Arithmetic/Logic unit with add/sub, AND, OR, set less than
port(a, b: in STD_LOGIC_VECTOR(7 downto 0);
alucontrol: in STD_LOGIC_VECTOR(2 downto 0);
result: out STD_LOGIC_VECTOR(7 downto 0);
statusrego: out STD_LOGIC_VECTOR(7 downto 0);
statusregi: in STD_LOGIC_VECTOR(7 downto 0));
end;
architecture behave of alu is
signal r: std_logic_vector(7 downto 0);
begin
result <= r;
with alucontrol(2 downto 0) select r <=
a and b when "010",
a or b when "001",
a xor b when "011",
a - b when "110",
a + b when "101",
a when "000",
"--------" when others;
statusRegUpdate:process ( r, alucontrol ) is
variable i,t,h,s,v,n,z,c: std_logic;
begin
if alucontrol = "010" or alucontrol = "001" or alucontrol = "011" then
n := r(7);
v := '0';
if r = "00000000" then
z := '1';
else
z := '0';
end if;
s := n xor v;
elsif alucontrol = "100" then
h := (not a(3) and b(3)) or (b(3) and r(3)) or (r(3) and not a(3));
if r = "00000000" then
z := '1';
else
z := '0';
end if;
v := (a(7) and not b(7)) and (not r(7) or not a(7)) and (b(7) and r(7));
n := r(7);
s := n xor v;
c := (not a(7) and b(7)) or (b(7)and r(7)) or (r(7) and not a(7));
elsif alucontrol = "101" then
h := (a(3) and b(3)) or (b(3) and not r(3)) or (not r(3) and a(3));
n := r(7);
v := (a(7) and b(7)) and (not r(7) or not a(7)) and (not b(7) and r(7));
s := n xor v;
if r = "00000000" then
z := '1';
else
z := '0';
end if;
c := (a(7) and b(7)) or (b(7) and not r(7)) or (not r(7) and a(7));
else
i := statusregi(7);
t := statusregi(6);
h := statusregi(5);
s := statusregi(4);
v := statusregi(3);
n := statusregi(2);
z := statusregi(1);
c := statusregi(0);
end if;
statusrego <= i&t&h&s&v&n&z&c;
end process;
end;