-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathULASomaSub.vhd
32 lines (29 loc) · 1.22 KB
/
ULASomaSub.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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; -- Biblioteca IEEE para funções aritméticas
entity ULASomaSub is
generic ( larguraDados : natural := 8 );
port (
entradaA, entradaB: in STD_LOGIC_VECTOR((larguraDados-1) downto 0);
seletor: in STD_LOGIC_VECTOR(1 downto 0);
saida: out STD_LOGIC_VECTOR((larguraDados-1) downto 0);
flagZero, flagMenor: out std_logic
);
end entity;
architecture comportamento of ULASomaSub is
signal soma : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
signal subtracao : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
signal passa : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
signal andi : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
begin
soma <= STD_LOGIC_VECTOR(unsigned(entradaA) + unsigned(entradaB));
subtracao <= STD_LOGIC_VECTOR(unsigned(entradaA) - unsigned(entradaB));
andi <= STD_LOGIC_VECTOR(unsigned(entradaA) and unsigned(entradaB));
passa <= entradaB;
saida <= andi when (seletor = "11")
else passa when (seletor = "10")
else soma when (seletor = "01")
else subtracao;
flagZero <= '1' when (subtracao = x"00") else '0';
flagMenor <= subtracao(larguraDados-1);
end architecture;