-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalu.vhd
More file actions
36 lines (33 loc) · 1.29 KB
/
alu.vhd
File metadata and controls
36 lines (33 loc) · 1.29 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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity alu is
Port (
op_code : in STD_LOGIC_VECTOR (2 downto 0); -- کد عملیات
operand1 : in STD_LOGIC_VECTOR (15 downto 0); -- عملوند 1
operand2 : in STD_LOGIC_VECTOR (15 downto 0); -- عملوند 2
result : out STD_LOGIC_VECTOR (15 downto 0); -- نتیجه
zero_flag : out STD_LOGIC -- پرچم صفر برای نتیجه صفر
);
end alu;
architecture Behavioral of alu is
begin
process(op_code, operand1, operand2)
begin
case op_code is
when "000" => result <= operand1 + operand2; -- عملیات جمع
when "001" => result <= operand1 - operand2; -- عملیات تفریق
when "010" => result <= operand1 AND operand2; -- عملیات AND
when "011" => result <= operand1 OR operand2; -- عملیات OR
when "100" => result <= NOT operand1; -- عملیات NOT
when others => result <= (others => '0'); -- مقدار پیشفرض
end case;
-- تنظیم پرچم صفر
if result = "0000000000000000" then
zero_flag <= '1';
else
zero_flag <= '0';
end if;
end process;
end Behavioral;