-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.vhd
93 lines (83 loc) · 1.82 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- Copyright 2018 Takayuki Nagata All Rights Reserved.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
entity alu is
Port ( X : in STD_LOGIC_VECTOR (15 downto 0);
Y : in STD_LOGIC_VECTOR (15 downto 0);
O : out STD_LOGIC_VECTOR (15 downto 0);
zx : in STD_LOGIC;
nx : in STD_LOGIC;
zy : in STD_LOGIC;
ny : in STD_LOGIC;
f : in STD_LOGIC;
no : in STD_LOGIC;
zr : out STD_LOGIC;
ng : out STD_LOGIC);
end alu;
architecture Behavioral of alu is
signal X_int : STD_LOGIC_VECTOR (15 downto 0);
signal Y_int : STD_LOGIC_VECTOR (15 downto 0);
signal O_int_f : STD_LOGIC_VECTOR (15 downto 0);
signal O_int_n: STD_LOGIC_VECTOR (15 downto 0);
signal O_int: STD_LOGIC_VECTOR (15 downto 0);
begin
process(X, zx, nx)begin
if zx = '1' then
if nx = '1' then
X_int <= "1111111111111111";
else
X_int <= "0000000000000000";
end if;
else
if nx = '1' then
X_int <= not X;
else
X_int <= X;
end if;
end if;
end process;
process(Y, zy, ny)begin
if zy = '1' then
if ny = '1' then
Y_int <= "1111111111111111";
else
Y_int <= "0000000000000000";
end if;
else
if ny = '1' then
Y_int <= not Y;
else
Y_int <= Y;
end if;
end if;
end process;
process(X_int, Y_int, f)begin
if f = '1' then
O_int_f <= X_int + Y_int;
else
O_int_f <= X_int and Y_int;
end if;
end process;
process(O_int_f, no)begin
if no = '1' then
O_int_n <= not O_int_f;
else
O_int_n <= O_int_f;
end if;
end process;
O_int <= O_int_n;
process(O_int)begin
if O_int = "0" then
zr <= '1';
ng <= '0';
elsif O_int < "0" then
zr <= '0';
ng <= '1';
else
zr <= '0';
ng <= '0';
end if;
end process;
O <= O_int;
end Behavioral;