-
Notifications
You must be signed in to change notification settings - Fork 0
/
ULASomaSub.vhd
30 lines (25 loc) · 1.06 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
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 := 4 );
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);
flag: 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);
begin
soma <= STD_LOGIC_VECTOR(unsigned(entradaA) + unsigned(entradaB));
subtracao <= STD_LOGIC_VECTOR(unsigned(entradaA) - unsigned(entradaB));
passa <= entradaB;
saida <= soma when (seletor = "01") else
subtracao when(seletor = "00") else
passa;
flag <= not (Saida(7) or Saida(6) or Saida(5) or Saida(4) or Saida(3) or Saida(2) or Saida(1) or Saida(0));
end architecture;