-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.vhd
25 lines (24 loc) · 852 Bytes
/
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity alu is
Port (
A,B : in STD_LOGIC_VECTOR (31 downto 0);
alu_control : in STD_LOGIC_VECTOR (3 downto 0);
zero : out STD_LOGIC;
result : out STD_LOGIC_VECTOR (31 downto 0));
end alu;
architecture behavioral of alu is
begin
result <= A + B when alu_control="0010" else
A - B when (alu_control="0110" or alu_control="0011") else
A and B when alu_control="0000" else
A or B when alu_control="0001" else
"00000000000000000000000000000001" when (alu_control="0111" and A < B) else
"00000000000000000000000000000000" when alu_control="0111";
zero <= '1' when (A/=B and alu_control="0011") else
'0' when(A=B and alu_control="0011") else
'1' when A=B else
'0';
end behavioral;